Code pasted

空格替换

http://www.nowcoder.com/questionTerminal/b0850698cb41449188344cdb647f3e99

class Replacement {
public:
    string replaceSpace(string iniString, int length) {
        // count zeros
        int last = length + 2 * count(iniString.begin(), iniString.begin()+length, ' ');
        iniString.resize(last);
        // reverse filling
        for (int i = length-1, j = last-1; i >= 0; --i) {
            if (iniString[i] != ' ') iniString[j--] = iniString[i];
            else {
                iniString.replace(j-2, 3, "%20");
                j -= 3;
            }
        }
        return iniString;
    }
};
全部评论

相关推荐

野猪不是猪🐗:我assume that你must技术aspect是solid的,temperament也挺good的,however面试不太serious,generally会feel style上不够sharp
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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