My python code


  • 0
    Y

    Sharing my solution with community. Thanks.

    class Solution(object):
        def plusOne(self, digits):
            carry = 1
            i = len(digits) - 1
            
            while i >= 0 and carry > 0:
                segment = (digits[i] + carry) % 10
                carry = 1 if segment == 0 else 0
                
                digits[i] = segment
                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.