leetcode solution in c++ and python