From 26b71d6d46fda9c6089e0889df1d38f3273b8386 Mon Sep 17 00:00:00 2001 From: Luis Rodrigues Date: Wed, 12 Feb 2025 16:52:43 +0000 Subject: [PATCH] exercicio 283 resolvido em python --- 283-move_zeroes/python/283.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/283-move_zeroes/python/283.py b/283-move_zeroes/python/283.py index c354e09..d66c59e 100644 --- a/283-move_zeroes/python/283.py +++ b/283-move_zeroes/python/283.py @@ -7,18 +7,18 @@ # 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(self, nums: list[int]) -> None: + +def moveZeroes(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 + 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