Clear Python solution


  • 0
    B
    class Solution(object):
        def plusOne(self, digits):
            """
            :type digits: List[int]
            :rtype: List[int]
            """
            for i in reversed(range(len(digits))):
                if digits[i] == 9:
                    digits[i] = 0
                    if i == 0:
                        digits.insert(0, 1)
                else:
                    digits[i] += 1
                    break
            return digits

Log in to reply
 

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