Solution to LeetCode