lc283. 移动零
class Solution: def moveZeroes(self, nums: List[int]) -> None: """ Do not return anything, modify nums in-place instead. """ i, j = 0, 0 while j < len(nums): if nums[j] != 0 and i == j: i += 1 elif nums[j] != 0 and i != j: nums[i] = nums[j] i += 1 j += 1 # i后面全补0(包括i) while i < len(nums): nums[i] = 0 i += 1
浙公网安备 33010602011771号