simple python solution using while loop


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

Log in to reply
 

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