双指针法
class Solution {
public:
string replaceSpace(string s) {
int len = s.length(),count=0;
for(auto c : s){
if(c == ' ') count++;
}
s.resize(len + 2*count);
int i = len-1 , j = s.length() - 1;
for( ; i!=j ; i--,j--){
if(s[i] != ' ')
s[j] = s[i];
else{
s[j] = '0';
s[j-1] = '2';
s[j-2] = '%';
j -=2 ;
}
}
return s;
}
};