"""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. """ from typing import List class Solution: def plusOne(self, digits: List[int]) -> List[int]: n = len(digits) # Start from the rightmost digit for i in range(n - 1, -1, -1): # If the current digit is less than 9, just increment it by 1 and return if digits[i] < 9: digits[i] += 1 return digits # Otherwise, set the current digit to 0 and continue with the next digit else: digits[i] = 0 # If we reach here, it means all digits were 9, so we need to add a new leading 1 digits.insert(0, 1) return digits