mycode
Mainly when calculating the quotient and remainder of the quotient and remainder must use not updated oh
class Solution(object): def plusOne(self, digits): """ :type digits: List[int] :rtype: List[int] """ add = 1 for i in range(len(digits)-1,-1,-1): digits[i],add= (digits[i] + add) % 10,(digits[i] + add) // 10 if add : digits.insert(0,add) return digits
reference:
def plusOne(self, digits): j = len(digits) - 1 cout = 1 while(j >= 0 and cout): digits[j] += cout cout, digits[j] = digits[j] // 10, digits[j] % 10 j -= 1 return digits if not cout else [cout] + digits