Leetcode Question 3 Solution