Move Zeroes
EasyP1Coding
Move every 0 in nums to the end of the array while keeping the relative order of the non-zero elements. Do it in place, without making a copy of the array.
Example 1
- Input
- nums = [0,1,0,3,12]
- Output
- [1,3,12,0,0]
Example 2
- Input
- nums = [0]
- Output
- [0]
Example 3
- Input
- nums = [4,0,5,0,0,6]
- Output
- [4,5,6,0,0,0]
Constraints
- 1 <= nums.length <= 10^4
- -2^31 <= nums[i] <= 2^31 - 1
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 3 visible tests, Submit all 8. ⌘Enter runs, ⌘⇧Enter submits.