1: class Solution {
2: public:
3: void reverseWords(string &s) {
4: reverse(s.begin(), s.end());
5: int i = 0, j = 0;
6: while (i < s.size()) {
7: while (i < s.size() && s[i] != ' ') i++;
8: reverse(s.begin()+j, s.begin()+i);
9: j = ++i;
10: }
11: }
12: };
No comments:
Post a Comment