Skip to content

Commit 10eda2f

Browse files
authored
Add files via upload
1 parent bf1e958 commit 10eda2f

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

151.Reverse Words In string.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution {
2+
public:
3+
string reverseWords(string s) {
4+
stringstream ss (s);
5+
string word, result;
6+
7+
vector<string> words;
8+
while (ss>>word) words.push_back(word);
9+
10+
11+
reverse(words.begin(), words.end());
12+
13+
for(int i =0; i<words.size(); i++)
14+
{
15+
if (i>0) result +=" ";
16+
result+=words[i];
17+
}
18+
return result;
19+
20+
}
21+
};

0 commit comments

Comments
 (0)