exercicio 283 resolvido em python
This commit is contained in:
@ -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
|
||||
|
||||
Reference in New Issue
Block a user