added C++ solution