Question

Formatted question description: https://leetcode.ca/all/283.html

 283. Move Zeroes

Given an array nums, write a function to move all 0's to the end of it
while maintaining the relative order of the non-zero elements.

Example:

Input: [0,1,0,3,12]
Output: [1,3,12,0,0]

Note:

You must do this in-place without making a copy of the array.
Minimize the total number of operations.

@tag-array



Algorithm

To do in-place replacement method, you need to use two pointers, one of which keeps sweeping backwards to find a non-zero position, and then swap positions with the previous pointer.

Java