class Solution { public: string reverseWords(string s) { string temp; string ret; for (int i = 0; i < s.length(); i++) { if (s.at(i) == ' ') { reverse(temp.begin(), temp.end()); ret += temp + " "; temp.clear(); continue; } temp += s.at(i); } if (s.length() > 0) { reverse(temp.begin(), temp.end()); ret += temp; } return ret; } };