Blog Domain name: Http://www.xnerv.wang
Original title page: https://oj.leetcode.com/problems/plus-one/
Topic Type: Analog numerical operations
Difficulty Evaluation: ★
This article address: http://blog.csdn.net/nerv3x3/article/details/37336603
Given a non-negative number represented as an array of digits, plus one to the number.
The digits are stored such this most significant is in the head of the list.
An int array represents a numeric value, the leftmost is the highest, and now requires 1, and returns an array of int to represent the results of the calculation.
Very simple analog addition, note the carry problem, if it is 99,999 this, and finally add 1 after the array to the left to insert an element 1.
Space complexity O (1). Time complexity O (N).
class Solution: # @param digits, a list of integer digits # @return A list of integers digits
def plusone (self, digits): len_s = len (digits) Carry = 1 for I in range (len_s-1,-1,-1): Total = digits[i] + carry digit = Int (total%) carry = Int (TOTAL/10) dig Its[i] = Digit if 1 = = Carry:digits.insert (0, 1) return digits