Moving Zeros
Given an arraynums
, write a function to move all0
's to the end of it while maintaining the relative order of the non-zero elements.
Example
Givennums = [0, 1, 0, 3, 12]
, after calling your function,nums
should be[1, 3, 12, 0, 0]
.
Note
when not zero override the value of the left and right pointer will go through the array; give 0 for ones after left pointer
swap with left when not zero and right pointer will go through the array (quicker)
Code
Last updated