283. 移动零
题解:
使用双指针法(快慢指针),快指针指向的数字不为0的时候,将这个数字移到慢指针的地方,最后在后面补0即可
class Solution:def moveZeroes(self, nums: List[int]) -> None:"""Do not return anything, modify nums in-place instead."""slow = 0for fast in range(len(nums)):if nums[fast] != 0:nums[slow] = nums[fast]slow += 1for i in range(slow, len(nums)):nums[i] = 0return nums