C++ solution for LeetCode