Sword Finger Offer Interview Question 58-I。単語の順序を反転する[シンプル]-istringstream

LeetCode151と同じです。

私の解決策:

sが空であるか、スペースしかないことに注意してください

class Solution {
public:
    string reverseWords(string s) {
        if(s.empty())   return "";
        istringstream word(s);
        string w;
        string res;
        while(word>>w){
            res=w+' '+res;
        }
        return res.empty()?"":string(res.begin(),res.end()-1);
    }
};

元の65の記事を公開 賞賛1 訪問482

おすすめ

転載: blog.csdn.net/qq_41041762/article/details/105478590