Move Zeroes
Problem statement
Given an integer array nums, move every zero to the end while preserving the relative order of all nonzero values. Return the transformed array.
The returned-array interface represents the standard in-place task for portable execution.
Function
moveZeroes(nums: int[]) → int[]Examples
Example 1
nums = [0,1,0,3,12]return = [1,3,12,0,0]The nonzero values remain in their original order and both zeroes move to the suffix.
Example 2
nums = [0]return = [0]A one-zero array is unchanged.
Constraints
0 <= nums.length <= 10^5.- Each value is a signed 32-bit integer.