This is my python AC code


  • 0
    L
    class Solution:
    # @param digits, a list of integer digits
    # @return a list of integer digits
    def plusOne(self, digits):
        count = len(digits) - 1
        while count >= 0:
            if digits[count] == 9:
                digits[count] = 0
            else:
                digits[count] = digits[count] + 1
                break
            count -= 1
        if digits[0] == 0:
            digits.append(1)
            digits = digits[::-1]
        return digits

  • 0
    D

    share my python solution too.

    class Solution:
        # @param digits, a list of integer digits
        # @return a list of integer digits
        def plusOne(self, digits):
            length = len(digits)-1
            carrier = 1
            while carrier == 1 and length >= 0:
                num = carrier + digits[length]
                digits[length] = num%10
                carrier = num/10
                length -= 1
            if carrier == 1:
                digits.insert(0,1)
            return digits

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.