my leetcode answer, using cpp