题解 | #翻转单词序列#

翻转单词序列

https://www.nowcoder.com/practice/3194a4f4cf814f63919d0790578d51f3

class Solution {
public:
    string ReverseSentence(string str) {
        string temp,res;
        for(int i=str.size()-1;i>-1;i--){
            if(str[i]!=' ')
                temp.push_back(str[i]);
            else{
                reverse(temp.begin(),temp.end());
                res+=temp+" ";
                temp.clear();
            }
        }
        reverse(temp.begin(),temp.end());
        res+=temp;
        return res;
    }
};

全部评论

相关推荐

醉蟀:你不干有的是人干
点赞 评论 收藏
分享
05-09 14:45
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务