version 1 of solution for leetcode