Move Zeroes
Easy
LC #283
in placeread/write pointersNot attempted yet
Move every 0 in nums to the end while keeping the
relative order of the non-zero values.
Do it in place: modify nums directly and don't return
anything (the tests inspect nums after your call).
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, 0, -2, 5]
Output: [4, -2, 5, 0, 0]
Constraints
- 1 ≤ len(nums) ≤ 10⁵
- -2³¹ ≤ nums[i] ≤ 2³¹ - 1
- O(1) extra space; don't build a new list