剑指offer05替换字符串空格

# coding:utf-8
"""
Name : 剑指offer05.py
Author  : qlb
Contect : 17801044486@163.com
Time    : 2021/2/7 9:56
Desc: 替换字符串空格
"""
# python 字符串不可原地修改 因此先将字符串转换为列表
class Solution:
    def replaceSpace(self, s: str) -> str:
        s = list(s)
        for i in range(len(s)):
            if s[i] == ' ':
                s[i] = "%20"
        return  ''.join(s)

 

posted @ 2021-02-07 10:33  qilibin  阅读(32)  评论(0编辑  收藏  举报