solution for leetcode.com