Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- string reverseWords(string s) {
- istringstream in(s);
- vector<string>a;
- string ans;
- string word;
- while(in >> word)
- {
- a.push_back(word);
- //cout<<word<<" ";
- }
- for(int i=(int)a.size()-1; i>=0; i--)
- {
- if(i == (int)a.size()-1)
- ans=a[i];
- else
- ans +=" "+a[i];
- cout<<a[i]<<" ";
- }
- return ans;
- }
- };
Add Comment
Please, Sign In to add comment