题目描述
替换空格
样例
class Solution {
public:
string replaceSpace(string s) {
int len = 0;
for (auto x: s) {
if (x == ' ')
len += 3;
else
len++;
}
int i = s.size() - 1, j = len - 1;
s.resize(len);
while (i >= 0) {
if (s[i] == ' ') {
s[j--] = '0';
s[j--] = '2';
s[j--] = '%';
} else {
s[j--] = s[i];
}
i--;
}
return s;
}
};