My solution in leetcode problem