LeetCode Challenge (Python3). Problem 2