Leetcode Solution 9