Leon's Leetcode solution