Easyarraystwo pointers
Move Zeroes
Shift every zero to the end while keeping the other values in order.
Move every 0 in nums to the end of the array, keeping the relative order of the non-zero values unchanged.
Return the resulting array.
Constraints
- 0 ≤ nums.length ≤ 10,000
- -10⁹ ≤ nums[i] ≤ 10⁹
Examples
- Input
- nums = [0,1,0,3,12]
- Output
- [1,3,12,0,0]
- Why
- Non-zeroes keep their order; two zeroes go to the back.
- Input
- nums = [0,0,1]
- Output
- [1,0,0]
- Input
- nums = [1,2,3]
- Output
- [1,2,3]
- Why
- Nothing to move.
Submitting also runs 6 hidden tests.
Limits
2000 ms and 256 MB per test case.