Easy

Quiz

#283 Move Zeroes

APPROACH

Given an integer array nums, relocate all 0 elements to the end of the array while preserving the relative order of the non-zero elements.

This must be done in-place without making a copy of the array.

Example 1:

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

Example 2:

Input: nums = [0]
Output: [0]
1 of 4
1:00

What is the optimal approach for this problem?