class Solution {
public:
void reverseWords(string &s) {
vector<string> temp;
string str;
for(int i=0;i<s.length();i++)
{
if(s[i]!=' ')
{
str=str+s[i];
}
else
{
if(str.size()!=0)
{
temp.push_back(str);
str.clear();
}
}
}
if(str.size()!=0)
temp.push_back(str);
s.clear();
for(int i=0;i<temp.size();i++)
{
s=s+temp[temp.size()-i-1];
if(i!=temp.size()-1)
s=s+' ';
}
}
};
不用脑子的办法