Algo TraceLEETCODE 283 · TWO POINTERS移动零READY01 / 21EXAMPLE 01 / 03交换零与后续非零数nums = [0, 1, 0, 3, 12]01交换零与后续非零数nums = [0, 1, 0, 3, 12]02跳过自身交换,slow 仍前进nums = [1, 2, 3]03全为零,slow 始终不动nums = [0, 0, 0]00112033412slowslow 0fast -1nums[fast] —slow 从索引 0 开始slow 记录下一个非零数应该放置的位置LINE 01slow = 0PYTHON1slow = 02for 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 += 1TIMEO(n)SPACEO(1)