题目链接:https://leetcode-cn.com/problems/ti-huan-kong-ge-lcof/
思路:
创建一个新的字符串,遍历原来字符串,到空格替换为%20即可。
class Solution {
public:
string replaceSpace(string s) {
string new_s = "";
for(int i = 0;i<s.size();i++)
{
if(s[i] == ' ')
new_s += "%20";
else
new_s += s[i];
}
return new_s;
}
};