Skip to content

Commit e2a607b

Browse files
authored
557. Reverse Words in a String III
1 parent 8cc209d commit e2a607b

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

557. Reverse Words in a String III

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//T.C - O(n)
2+
//S.C - O(1)
3+
4+
public:
5+
string reverseWords(string s) {
6+
int i=0;
7+
for(int j=0;j<s.size();j++) {
8+
if(s[j] == ' '){
9+
reverse(s.begin() +i,s.begin() +j);
10+
i = j+1;
11+
}
12+
}
13+
reverse(s.begin() +i,s.end());
14+
return s;
15+
}

0 commit comments

Comments
 (0)