【leetcode C++】【剑指 Offer】 05. 替换空格

剑指 Offer 05. 替换空格

在这里插入图片描述

class Solution {
    
    
public:
    string replaceSpace(string s) {
    
    
        string ans = "";
        for(auto ch : s) {
    
    
            if(ch == ' ') ans += "%20";
            else ans += ch;
        }
        return ans;
    }
};

猜你喜欢

转载自blog.csdn.net/m0_37454852/article/details/114385164