Example 1
Input
nums = [0, 1, 0, 3, 12]
Output
[1, 3, 12, 0, 0]
Loading CodeSprint...
/problems/move-zeroes
Return an array with every zero moved to the end while preserving the relative order of all nonzero values.
Implement this function and return the result. CodeSprint supplies each test case automatically.
moveZeroes(nums) → number[]Input
nums = [0, 1, 0, 3, 12]
Output
[1, 3, 12, 0, 0]
Input
nums = [0]
Output
[0]
Constraints
0 <= nums.length <= 100,000 -1,000,000,000 <= nums[i] <= 1,000,000,000