LeetCode151と同じです。
私の解決策:
sが空であるか、スペースしかないことに注意してください
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);
}
};