算法空间/Leetcode/替换空格:修订间差异
来自康健生活
创建页面,内容为“== 题目描述 == 实现一个函数,把字符串中的每个空格替换成 <code>%20</code>。 == 示例 == # 输入 <code>We are happy.</code> # 输出 <code>We%20are%20happy.</code> == 实现 == <syntaxhighlight lang="javascript"> var pathEncryption = function (path) { let cup = '' for (let i = path.length - 1; i >= 0; i--) { cup = (path[i] === '.' ? ' ' : path[i]) + cup } return cup };</syntaxhighlight> == 结论 == 打开 lee…” |
|||
| 第18行: | 第18行: | ||
== 结论 == | == 结论 == | ||
打开 leetcode 发现本题已经被替换为 [https://leetcode.cn/problems/ti-huan-kong-ge-lcof/description/ LCR 122. 路径加密],本实现的解题思路是利用<code>不断重置引用地址的存储内容</code>,复杂度是 <math>O(N)</math>。 | 打开 leetcode 发现本题已经被替换为 [https://leetcode.cn/problems/ti-huan-kong-ge-lcof/description/ LCR 122. 路径加密],本实现的解题思路是利用<code>不断重置引用地址的存储内容</code>,复杂度是 <math>O(N)</math>。 | ||
<pre> | |||
执行用时分布 0ms | |||
消耗内存分布 54.09MB | |||
</pre> | |||