28. Move Zeroes

Move all zeroes to the end of the array while preserving the order of the other elements.
Example 1
Input: nums = [0,1,0,3,12]
Output: [1,3,12,0,0]
Explanation: First shift non-zeros to the left [1,3,12], then fill remaining positions with zeros => [1,3,12,0,0].
Example 2
Input: nums = [1,2,3]
Output: [1,2,3]
Explanation: No zeros — array remains [1,2,3].
Example 3
Input: nums = [0,0,1]
Output: [1,0,0]
Explanation: Non-zero elements [1] at the beginning, then two zeros on the right => [1,0,0].
arraysmedium
JavaScript
Loading...
Line 1, Char 1