class Solution:
def replaceSpace(self, s: str) -> str:
counter = s.count(' ')
res = list(s)
res.extend([' ']*counter*2)
front = len(s)-1
rear = len(res)-1
while front >= 0:
if res[front] == ' ':
res[rear-2:rear+1] = '%20' #左闭右开
rear -= 3
else:
res[rear] = res[front]
rear -= 1
front -= 1
return ''.join(res)
03-14
829
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)