diff --git a/66-plus_one/python/66.py b/66-plus_one/python/66.py new file mode 100644 index 0000000..02058de --- /dev/null +++ b/66-plus_one/python/66.py @@ -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