Leetcode 399 Python Recursive Function