283. Move Zeroes
[Easy] “Given an array nums, write a function to move all 0’s to the end of it while maintaining the relative order of the non-zero elements."
Note: old solution, should review (TODO:
)
Python3:
class Solution:
def moveZeroes(self, nums: List[int]) -> None:
"""
Do not return anything, modify nums in-place instead.
"""
count_zeros = 0
i = 0
while i < len(nums):
if nums[i] == 0:
count_zeros += 1
del nums[i]
else:
i += 1
nums.extend([0] * count_zeros)