python LeetCode solution