class Solution {
public:
string reverseWords(string s) {
int slow = 0,fast = 0;
while(fast < s.size())
{
fast++;
if(s[fast] == ' ' || fast == s.size())
{
reverse(s,slow,fast);
slow = ++fast;
}
}
return s;
}
void reverse(string &s,int slow,int fast)
{
while(slow < (fast-1))
{
char tmp = s[slow];
s[slow] = s[fast-1];
s[fast-1] = tmp;
fast--;
slow++;
}
}
};