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.

Example:

Input: [0,1,0,3,12]
Output: [1,3,12,0,0]
Note:

You must do this in-place without making a copy of the array.
Minimize the total number of operations.

Solution 1:

``````func moveZeroes(nums []int)  {
lenN := len(nums)

for needScan := true; needScan == true; {
needScan = false
for i := lenN - 1; i > 0; i-- {
if nums[i-1] == 0 && nums[i] != 0 {
nums[i-1] = nums[i]
nums[i] = 0
needScan = true
}
}
}
}
``````

Solution 2:

``````func moveZeroes(nums []int)  []int{
lenN := len(nums)
x, y := 0,0
for y < lenN {
if nums[y] != 0 {
nums[x], nums[y] = nums[y], nums[x];
y++
x++
}else {
y++
}
}
return nums
}
``````

**Solution 3: **

``````/*[0,1,0,3,12]
//cur = 0
lastN = 0
//  cur= 1
nums[0]= 1, nums[1] = 0  , [1,0,0 ,3, 12]
lastN++ = 1

// cur = 2
non;   nums = [1,0,0 ,3, 12]
// cur = 3
nums[1] = 3
nums[3] = 0
nums = [1,3,0,0,12]
lastN++ = 2
//cur = 4;
nums[2] = 4
nums[4] = 0

Notice: "lastNonZeroFoundAt" recogize  the first zero
*/

func moveZeroes(nums []int)  {
lastNonZeroFoundAt := 0
for cur := 0; cur < len(nums); cur++ {
if nums[cur] != 0 {
nums[lastNonZeroFoundAt] = nums[cur]

if lastNonZeroFoundAt != cur {
nums[cur] = 0
}
lastNonZeroFoundAt++

}
}
}

``````