01. Reverse Words in a String III
My Approach
Time and Auxiliary Space Complexity
Code (C++)
class Solution {
public:
string reverseWords(string s) {
int start=0,end=0;
while(start<s.length()){
while(end<s.length() && s[end]!= ' '){
end++;
}
reverse(s.begin()+start,s.begin()+end);
start=end+1;
end=start;
}
return s;
}
};
Contribution and Support
Last updated