剑指 Offer 58 - I. 翻转单词顺序

剑指 Offer 58 - I. 翻转单词顺序

class Solution {
public:
    string reverseWords(string s) {
        stringstream ssin(s);
        string res,word;
        while(ssin>>word){
            res=word+" "+res;
        }
        if(res.size())res.pop_back();
        return res;
    }
};

你可能感兴趣的:(剑指 Offer 58 - I. 翻转单词顺序)