Python: Recursion


  • 0
    P

    '''
    class Solution(object):

    def plusOne(self, digits):
        """
        :type digits: List[int]
        :rtype: List[int]
        """
        if digits == [9]:
            return [1, 0]
        elif digits[-1] == 9:
            return self.plusOne(digits[:-1]) + [0]
        else:
            digits[-1] += 1
            return digits
    

    '''


Log in to reply
 

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