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.
|
# Note that you must do this in-place without making a copy of the array.
|
||||||
|
|
||||||
# exemplo: dada a cadeia '00001' resultado final é '10000'
|
# 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.
|
Do not return anything, modify nums in-place instead.
|
||||||
"""
|
"""
|
||||||
for i in range(len(nums)):
|
for p_esq in range(len(nums)):
|
||||||
for j in range(i+1, len(nums)):
|
if nums[p_esq] == 0:
|
||||||
if nums[j] != 0:
|
for p_dto in range(p_esq, len(nums)):
|
||||||
nums[i] = nums[j]
|
if nums[p_dto] != 0:
|
||||||
nums[j] = 0
|
nums[p_esq] = nums[p_dto]
|
||||||
|
nums[p_dto] = 0
|
||||||
if nums[i] == 0 and i < len(nums)-1:
|
break
|
||||||
if nums[i+1] != 0:
|
continue
|
||||||
nums[i] = nums[i+1]
|
|
||||||
nums[i+1] = 0
|
|
||||||
|
|||||||
Reference in New Issue
Block a user