Python - Simple Solution


  • 0
    S
    
    class Solution(object):
        def plusOne(self, digits):
            """
            :type digits: List[int]
            :rtype: List[int]
            """
            carry = 1
            for i in range(len(digits)-1, -1, -1):
                num = carry + digits[i]
                if (num > 9):
                    carry = 1
                else:
                    carry = 0
                digits[i] = num%10
            
            if carry == 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.