题目链接:https://leetcode-cn.com/problems/ti-huan-kong-ge-lcof/
难度:简单

描述:
请实现一个函数,把字符串 s 中的每个空格替换成”%20”。

题解

  1. class Solution:
  2. def replaceSpace(self, s: str) -> str:
  3. ret = []
  4. for c in s:
  5. if c == " ":
  6. ret.append("%20")
  7. else:
  8. ret.append(c)
  9. return "".join(ret)