[LeetCode]Reverse Words in a String

来源:互联网 发布:信息过滤软件 编辑:程序博客网 时间:2024/06/03 21:23
Given an input string, reverse the string word by word.


For example,
Given s = "the sky is blue",

return "blue is sky the".

class Solution {public:    void reverseWords(string &s) {        std::stringstream ss(s);std::string word;std::vector< std::string> temp;while (ss>>word){temp.push_back(word);temp.push_back(" ");}s = "";for (int i = temp.size() - 2; i >= 0; i--){s += temp[i];}    }};




0 0