CC189 - 1.3

highlight:

1.in place: from back to the front

string URLify(string str, int len){
    int trueLen = len;
    for(int i=0;i<len;i++){
        if(str[i]==' '){
            trueLen += 2;
        }
    }
    str[trueLen] = '\0';
    while(len>0){
        trueLen--;
        len--;
        if(str[len]==' '){
            str[trueLen--] = '0';
            str[trueLen--] = '2';
            str[trueLen] = '%';
        }else{
            str[trueLen] = str[len];
        }
    }
    return str;
}

猜你喜欢

转载自blog.csdn.net/real_lisa/article/details/89742154
1.3