Added C++ solution.