dsa · easy
Move Zeroes
GreyOrangeArrayTwo PointersFoundation
Given an integer array nums, move all 0s to the end of it while maintaining the relative order of the non-zero elements. Return the array. Note that you must do this in-place without making a copy of the array.
Arguments
nums— the input array of integers
**Example 1:** `` Input: nums = [0,1,0,3,12] Output: [1,3,12,0,0] ``
Constraints
1 <= nums.length <= 4*10^4 Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.
Examples
Example 1
Input: [0,1,0,3,12] Expected: [1,3,12,0,0]
Example 2
Input: [0] Expected: [0]