""" 移动零 """ from typing import List class Solution: def moveZeroes(self, nums: List[int]) -> None: """ Do not return anything, modify nums in-place instead. """ i = 0 j = 0 while j < len(nums): if nums[j] != 0: nums[i] = nums[j] i += 1 j += 1 for index in range(i, len(nums)): nums[index] = 0 print(nums) if __name__ == '__main__': Solution().moveZeroes([0, 1, 0, 3, 12])