Leetcode 557 Solution
This article provides solution to leetcode question 557 (reverse-words-in-a-string-iii)
Access this page by simply typing in "lcs 557" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/reverse-words-in-a-string-iii
Solution
class Solution {
public:
string reverseWords(string s) {
int l = 0;
while (l < s.size())
{
int r = l + 1;
while (s[r] != ' ' && r != s.size())
r++;
int next = r + 1;
r--;
while (l < r)
swap(s[l++], s[r--]);
l = next;
}
return s;
}
};