题目描述

请实现一个函数,将一个字符串中的每个空格替换成“%20”。例如,当字符串为We Are Happy.则经过替换之后的字符串为We%20Are%20Happy。

时间限制:1秒;空间限制:32768K;本题知识点: 字符串

解题思路

先通过‘ ‘将字符串str切分成list,再通过‘%20’组合成str。

Python代码:

# -*- coding:utf-8 -*-
class Solution:
    # s 源字符串
    def replaceSpace(self, s):
        # write code here
        list = s.split(' ')
        return '%20'.join(list)

 

相关文章:

  • 2021-11-24
  • 2021-06-22
  • 2021-07-23
  • 2021-07-03
  • 2021-08-02
  • 2022-12-23
猜你喜欢
  • 2021-09-22
  • 2021-09-18
  • 2021-07-18
  • 2022-01-12
  • 2021-10-13
  • 2021-12-29
  • 2021-07-28
相关资源
相似解决方案