leetcode/notes/src/substitute_spaces.md
2022-11-29 20:26:23 +08:00

16 lines
426 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 替换空格
[Leetcode](https://leetcode.cn/problems/ti-huan-kong-ge-lcof/)
请实现一个函数,把字符串 s 中的每个空格替换成"%20"。
示例 1
> 输入s = "We are happy."
>
> 输出:"We%20are%20happy."
![demo](https://tva1.sinaimg.cn/large/e6c9d24ely1go6qmevhgpg20du09m4qp.gif)
对于很多数组填充类问题,都可以先计算出扩展后数组的长度,然后从后往前双指针。