ntree.ai
ntree.aiMove Zeroes

Move Zeroes

easysolvedattempted

Given an array of integers nums, move every 0 to the end while keeping the order of the non-zero elements.

Modify the array in place and return nothing.

Example 1:

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

Example 2:

Input: nums = [1, 2, 3]
Output: nums = [1, 2, 3]

Constraints:

  • 1 <= length of nums <= 10^4
  • -2^31 <= nums[i] <= 2^31 - 1
def moveZeroes(nums: list[int]) -> None:
pass
 

Press Visualise to step through your code.