leetcode solution from mzhao