Same as LeetCode151.
My solution:
Note that s is empty or there are only spaces
class Solution {
public:
string reverseWords(string s) {
if(s.empty()) return "";
istringstream word(s);
string w;
string res;
while(word>>w){
res=w+' '+res;
}
return res.empty()?"":string(res.begin(),res.end()-1);
}
};