剑指 Offer 05. 替换空格
难度:简单
problem
请实现一个函数,把字符串 s 中的每个空格替换成”%20”。
示例:
现有矩阵 matrix 如下:
输入:s = "We are happy."
输出:"We%20are%20happy."
solution
- 直接使用replaceAll()
- split() + join()
- 遍历拼接
code
1 | /** |
1 | /** |
1 | /** |
难度:简单
请实现一个函数,把字符串 s 中的每个空格替换成”%20”。
示例:
现有矩阵 matrix 如下:
输入:s = "We are happy."
输出:"We%20are%20happy."
1 | /** |
1 | /** |
1 | /** |