Python: 2 one line solution and 1 recursive solution


  • 0
    G
    def plusOne(self, digits):
        return [int(i) for i in str(reduce(lambda x,y: x*10+y, digits) + 1)]
    
    def plusOne(self, digits):
        return [int(i) for i in str(int("".join([str(i) for i in digits])) + 1)]
    
    def plusOne(self, digits):        
        if not digits:
            return [1]
        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.