exercicio 66 resolvido em python
This commit is contained in:
22
66-plus_one/python/66.py
Normal file
22
66-plus_one/python/66.py
Normal file
@ -0,0 +1,22 @@
|
||||
# You are given a large integer represented as an integer array digits, where
|
||||
# each digits[i] is the ith digit of the integer. The digits are ordered from
|
||||
# most significant to least significant in left-to-right order. The large
|
||||
# integer does not contain any leading 0's.
|
||||
#
|
||||
# Increment the large integer by one and return the resulting array of digits.
|
||||
|
||||
# só é preciso incrementar o valor no ultimo indice
|
||||
# -> mas e se o numero for '129'? o resultado correcto será '130' e não '120'
|
||||
#
|
||||
|
||||
|
||||
def plusOne(digits: list[int]) -> list[int]:
|
||||
digits[-1] += 1
|
||||
for n_digit in range(len(digits) - 1, -1, -1):
|
||||
if digits[n_digit] == 10:
|
||||
digits[n_digit] = 0
|
||||
if n_digit == 0:
|
||||
digits.insert(0, 1)
|
||||
else:
|
||||
digits[n_digit - 1] += 1
|
||||
return digits
|
||||
Reference in New Issue
Block a user