Simple Python solution with FDA Graph


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

    alt text


Log in to reply
 

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