function moveZeroes(nums):
write = 0
for i in range(len(nums)):
if nums[i] != 0:
nums[write], nums[i] = nums[i], nums[write]
write += 1
The swap approach processes each element once. When nums[i] is non-zero, it lands at position write and write advances. Zeroes get pushed right without any extra pass. If write equals i, the swap is a no-op, so you don't waste time.
time, space.