File tree Expand file tree Collapse file tree 2 files changed +9
-5
lines changed
Expand file tree Collapse file tree 2 files changed +9
-5
lines changed Original file line number Diff line number Diff line change @@ -34,17 +34,17 @@ https://leetcode-cn.com/problems/move-zeroes/
3434
3535## 思路
3636
37- 如果题目没有要求 modify in-place 的话,我们可以先遍历一遍将包含 0 的和不包含 0 的存到两个数组,
38- 然后拼接两个数组即可。 但是题目要求 modify in-place, 也就是不需要借助额外的存储空间,刚才的方法
39- 空间复杂度是 O(n).
37+ 如果题目没有要求 modify in-place 的话,我们可以先遍历一遍将包含 0 的和不包含 0 的存到两个数组,然后拼接两个数组即可。 但是题目要求 modify in-place, 也就是不需要借助额外的存储空间,刚才的方法空间复杂度是 O(n).
4038
4139那么如果 modify in-place ,空间复杂度降低为 1 呢?
4240
43- 其实可以借助一个游标记录位置,然后遍历一次,将非 0 的原地修改,最后补 0 即可。
41+ 其实可以使用** 读写双指针** 来做。具体来说使用一个慢指针表示写指针,快指针表示读指针。
42+
43+ 具体来说:读指针不断往后移动。如果遇到非 0,则将读到的值写入写指针,触发写指针移动(其他情况写指针不动),读指针走到头算法结束。经过这样的处理,最终写指针的位置前面就是所有的非 0 数了, 最后将写指针后的 位置全部修改为 0 即可。
4444
4545## 关键点解析
4646
47- - 双指针
47+ - 读写双指针
4848
4949## 代码
5050
Original file line number Diff line number Diff line change @@ -34,6 +34,10 @@ https://leetcode-cn.com/problems/unique-binary-search-trees/
3434- 百度
3535- 字节
3636
37+ ## 岗位信息
38+
39+ - 腾讯(广州)- 安卓 - 社招 - 三面
40+
3741## 思路
3842
3943这是一个经典的使用分治思路的题目。
You can’t perform that action at this time.
0 commit comments