Leetcode Problem 2 Solution Python 3