my own solution for leetcode