题解 | #翻转单词序列#
翻转单词序列
https://www.nowcoder.com/practice/3194a4f4cf814f63919d0790578d51f3
class Solution {
public:
string ReverseSentence(string str) {
string temp,res;
for(int i=str.size()-1;i>-1;i--){
if(str[i]!=' ')
temp.push_back(str[i]);
else{
reverse(temp.begin(),temp.end());
res+=temp+" ";
temp.clear();
}
}
reverse(temp.begin(),temp.end());
res+=temp;
return res;
}
};

