My simple Python code


  • 0
    H

    This is an easy problem. Just follow the arithmetic rules and be careful of the carry.

    class Solution(object):
        def plusOne(self, digits):
            """
            :type digits: List[int]
            :rtype: List[int]
            """
            n = len(digits)
            i = n-1
            carry = 1
            while i>=0 and carry!=0:
                digits[i], carry = (digits[i]+carry)%10, (digits[i]+carry)//10
                i -= 1
            if i<0 and carry!=0: 
                digits.insert(0, carry)
            return digits
    

  • 0
    Z

    @HuTuo pretty brilliant one


Log in to reply
 

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