My solution for leetcode