java solution finished, added c++ solution