C++/题解:
先转为string,然后处理完成后再转为char *。但不是以返回值的形式,还要利用好原来的空间,用strcpy实现之。
C++/代码:
class Solution {
public:
void replaceSpace(char *str,int length) {
string res,s = str;
for (char x : s) {
if (x == ' ') res += "%20";
else res += x;
}
strcpy(str,res.c_str());
}
};
京公网安备 11010502036488号