Algo Trace

LEETCODE 283 · TWO POINTERS

移动零

READY01 / 21
00
11
20
33
412
slow
slow 0fast -1nums[fast] —

slow 从索引 0 开始

slow 记录下一个非零数应该放置的位置

slow = 0
PYTHON
1slow = 0
2for fast in range(len(nums)):
3 if nums[fast] != 0:
4 if fast != slow:
5 nums[fast], nums[slow] = nums[slow], nums[fast]
6 slow += 1
TIMEO(n)
SPACEO(1)

← → 步进 · Space 播放 / 暂停