solve LeetCode problem using python