My Leetcode solution