Skip to content

Instantly share code, notes, and snippets.

@xzhang311
Created March 30, 2016 04:43
class Solution {
public:
void reverseWords(string &s){
reverse(s.begin(), s.end());
auto l=s.begin();
auto r=s.begin();
while(l!=s.end()){
while(*r!=' '&& r!=s.end())
r++;
reverse(l, r);
l=r+1;
if(r==s.end())
break;
else
r++;
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment