My python solution.


  • 0
    Y
    class Solution(object):
        def plusOne(self, digits):
            """
            :type digits: List[int]
            :rtype: List[int]
            """
            len_digits = len(digits)
            jump = 1
            for index in range(len_digits-1, -1, -1):
                cur = digits[index] + jump
                jump, cur = divmod(cur, 10)
                digits[index] = cur
            if jump:
                digits.insert(0, jump)
            return digits
    

Log in to reply
 

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