letcode solution with python