Leetcode 399 Python Algorithm Practice