Leetcode Problem 2 Solution