题解 | #翻转单词序列#
翻转单词序列
http://www.nowcoder.com/practice/3194a4f4cf814f63919d0790578d51f3
题解 | #翻转单词序列#
```class Solution {
public:
string ReverseSentence(string str) {
int n=str.length();
string res;
for(int i=0;i<n;i++)
{
string tmp="";
while(str[i]!=' '&&i<n)
{
tmp+=str[i];
i++;
}
if(i<n)
{
tmp=str[i]+tmp;
}
res=tmp+res;
}
return res;
}
};
``` c++