Move Zeros

Given an array nums, move all of its zeros to the end while keeping the other numbers in the order they had. Return the resulting array.

Try doing it in place, without a second array (you still return nums).

Constraints

  • 1 ≤ length of nums ≤ 15,000
  • -1,000,000,000 ≤ nums[i] ≤ 1,000,000,000

Example 1

Input
nums = [0,1,0,3,12]
Output
[1,3,12,0,0]
Why:

1, 3 and 12 keep their order; the two zeros go last.

Example 2

Input
nums = [0]
Output
[0]
Why:

A single zero stays where it is.

Hints

    Was this a good challenge?

    Solved by
    0
    Submissions
    0
    Accepted
    –