primeiro commit

This commit is contained in:
2025-02-12 12:33:39 +00:00
commit 0204a191c7
7 changed files with 96 additions and 0 deletions

View File

@ -0,0 +1,24 @@
# 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'
def moveZeroes(self, nums: list[int]) -> None:
"""
Do not return anything, modify nums in-place instead.
"""
for i in range(len(nums)):
for j in range(i+1, len(nums)):
if nums[j] != 0:
nums[i] = nums[j]
nums[j] = 0
if nums[i] == 0 and i < len(nums)-1:
if nums[i+1] != 0:
nums[i] = nums[i+1]
nums[i+1] = 0