python easy way


  • 0
    H
    class Solution(object):
        def plusOne(self, digits):
            """
            :type digits: List[int]
            :rtype: List[int]
            """
            carry = 1
            for i in range(len(digits))[::-1]:
                carry,digits[i] = divmod(digits[i]+carry,10)
                if carry == 0:
                    break
                if carry ==1 and i == 0:
                    digits.insert(0,1)
            return digits

Log in to reply
 

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