题目来源:
leetcode题目,网址:面试题 01.03. URL化 - 力扣(LeetCode)
解题思路:
新建字符串,将空格修改即可。
解题代码:
- class Solution {
- public:
- string replaceSpaces(string S, int length) {
- S.erase(length);
- string res;
- for(int i=0;i<S.length();i++){
- if(S[i]==' '){
- res+="%20";
- }else{
- res+=S[i];
- }
- }
- return res;
- }
- };
总结:
无官方题解。