Simple python solution


  • 0
    def plusOne(self, digits):
            p = []
            carry = 1
            for n in reversed(digits):
                s = n + carry
                if s > 10:
                    carry = s % 10
                elif s == 10:
                    carry = 1
                    s = 0
                else:
                    carry = 0
                p = [s] + p
            if carry:
                p = [carry] + p
                
            return p
    

Log in to reply
 

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