Leetcode Solution Python 3