题解 | #替换空格#

替换空格

https://www.nowcoder.com/practice/0e26e5551f2b489b9f58bc83aa4b6c68

C++三行扬了:

class Solution {
public:
    string replaceSpace(string s) {
        int space, end = s.size() - 1;
        for (; (space = s.rfind(' ', end)) != string::npos; end = space) 
            s.replace(space, 1, "%20");
            
        return s;
    }
};


全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务