Move Zeroes

easy · array, two-pointers

Move Zeroes

Given an integer array nums, move all 0 values to the end while preserving the order of non‑zero elements. Return the resulting array.

Function signature

func MoveZeroes(nums []int) []int

Example

nums = [0,1,0,3,12]
output = [1,3,12,0,0]

Constraints

  • 1 <= len(nums) <= 200_000
  • -1_000_000_000 <= nums[i] <= 1_000_000_000

Notes

  • A two‑pointer approach works in O(n).
Run tests to see results
No issues detected