class Solution {
public:
void replaceSpace(char *str,int length) {
int blankNum = 0;
for(int i = 0; i <= length; i++){
if(str[i] == ' ')
blankNum++;
}
char *p = str + length;
char *q = p + blankNum*2;
for(int i = 0; i <= length; i++){
if(*p == ' '){
*q = '0';
q--;
*q = '2';
q--;
*q = '%';
q--;
}
else{
*q = *p;
q--;
}
p--;
}
}
};
来源:https://www.cnblogs.com/olajennings/p/12456303.html