Simple Python Solution


  • 0
    M
        def plusOne(self, digits):
            """
            :type digits: List[int]
            :rtype: List[int]
            """
            carry = 1
            for i in reversed(xrange(len(digits))):
                digits[i] += carry
                if digits[i] > 9:
                    digits[i] = digits[i] % 10
                    carry = 1
                else:
                    carry = 0
            return [carry] + digits if carry else digits
    

Log in to reply
 

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