Files
leetcode/283-move_zeroes/python/283.py

25 lines
767 B
Python

# 283. Move Zeroes
# https://leetcode.com/problems/move-zeroes/
#
# Given an integer array nums, move all 0's to the end of it while maintaining
# the relative order of the non-zero elements.
#
# Note that you must do this in-place without making a copy of the array.
# exemplo: dada a cadeia '00001' resultado final é '10000'
# '0123405' resultado final é '1234500'
def moveZeroes(nums: list[int]) -> None:
"""
Do not return anything, modify nums in-place instead.
"""
for p_esq in range(len(nums)):
if nums[p_esq] == 0:
for p_dto in range(p_esq, len(nums)):
if nums[p_dto] != 0:
nums[p_esq] = nums[p_dto]
nums[p_dto] = 0
break
continue