23. Move Zeroes
MediumArrays~12 min
Given an array of numbers, move every 0 to the end while keeping the relative order of the non-zero values.
Return the resulting array.
Examples
Example 1
- Input:
- nums = [0, 1, 0, 3, 12]
- Output:
- [1, 3, 12, 0, 0]
Example 2
- Input:
- nums = [0, 0]
- Output:
- [0, 0]
Constraints
0 <= nums.length <= 1000Relative order of non-zero values must be preserved.