Search for a command to run...
You are given an integer array nums.
Your task is to move all the 0s to the end of the array while keeping the relative order of non-zero elements the same.
You must do this in-place (no extra array allowed).
Try to minimize the number of operations.
Input
nums = [0,1,0,3,12]Output
[1,3,12,0,0]Input
nums = [0]Output
[0]Take all non-zero numbers and shift them forward.
Fill remaining positions with 0.
1 ⤠nums.length ⤠10ā“
-2³¹ ⤠nums[i] ⤠2³¹ - 1
Example 1
[0, 1, 0, 3, 12][1,3,12,0,0]Example 2
[0, 0, 1][1,0,0][0, 1, 0, 3, 12]
[1,3,12,0,0]