Zeros to the Back
You are given a list of integers nums. Return the list with every zero moved to the end, and every other number kept in the order it had.
Examples
nums = [0, 3, 0, 5, 8] → [3, 5, 8, 0, 0]
nums = [1, 2, 3] → [1, 2, 3]
nums = [0, 0, 4] → [4, 0, 0]Constraints
- Between 0 and 10,000 numbers, each between -1,000,000 and 1,000,000.
- Aim for O(n): place each number once.
Console
›Run to see what your code prints
Run checks the 3 visible cases here, in your browser. Submit runs all 7 on the judge, 4 of them hidden, and measures how your solution scales.
Expected is the reference solution's answer, from the judge. An input that breaks the statement's other rules may get any answer.