题目:
题目:
代码:
class Solution {
public:
void Reverse(string &s, int start, int end)
{
char tmp;
while(start < end)
{
tmp = s[start];
s[start] = s[end];
s[end] = tmp;
start++;
end--;
}
}
string reverseWords(string s)
{
size_t start = 0;
size_t end = 0;
while(start < s.size())
{
end = s.find(' ', start);
if(end == string::npos)
{
end = s.size();
break;
}
Reverse(s, start, end-1);
start = end+1;
}
Reverse(s, start, end-1);
return s;
}
};