LeetCode solution