与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);
}
};