Move Zeroes
EasyArrayTwo PointersIn-Place Operations
Given an integer array nums, write a function to move all 0's to the end of the array while maintaining the relative order of the non-zero elements.
Do this in-place without making a copy of the array, and try to minimize the total number of operations.
Constraints:
1 ⤠nums.length ⤠10ā“
-2³¹ ⤠nums[i] ⤠2³¹ - 1
Examples
Example 1
Input: [0, 1, 0, 3, 12]
Output: [1,3,12,0,0]
Example 2
Input: [0, 0, 1]
Output: [1,0,0]