Search⌘ K
AI Features

Solution: Move Zeroes

Explore how to rearrange an integer array by moving all zeroes to its end in-place. Learn to implement the two pointers approach effectively, preserving the order of non-zero elements while optimizing for time and space complexity.

Statement

Given an integer array, nums, rearrange the elements such that all 0s0's are moved to the end of the array, while the relative order of all non-zero elements is preserved.

Note: The operation must be performed in-place, without creating a copy of the array.

Constraints:

  • 11 \leq nums.length 104\leq 10^4 ...