python算法-1字符串-8空格替换

python算法-1字符串-8空格替换

 

def replaceBlank(str, length):
    s = ''
    for i in range(length):
        if str[i] == ' ':
            str[i] = '%20'
        s += str[i]
    return s


if __name__ == '__main__':
    str = "Mr John Smith"
    str = list(str)
    a = replaceBlank(str, len(str))
    print(a)

在线运行:https://pyleetcode.gitee.io/codes_html/SYL_1%E5%AD%97%E7%AC%A6%E4%B8%B2_7%E7%A9%BA%E6%A0%BC%E6%9B%BF%E6%8D%A2.html

 

你可能感兴趣的:(算法LeetCode)