Solution for LeetCode