In-Place Move Zeros to End of List
Given a list of integers nums
, put all the zeros to the back of the list by modifying the list in-place. The relative ordering of other elements should stay the same.
Can you do it in \(\mathcal{O}(1)\) additional space?
Constraints
0 ≤ n ≤ 100,000
wheren
is the length ofnums
https://binarysearch.com/problems/In-Place-Move-Zeros-to-End-of-List
Examples
Example 1
Input
- nums =
[0, 1, 0, 2, 3]
Output
- answer =
[1, 2, 3, 0, 0]
Explanation
Note that [1, 2, 3]
appear in the same order as in the input.
Leave a comment