A python solution. 32ms beats92.8%


  • 0
    L
        def plusOne(self, digits):
            digits[:] = digits[::-1]
            for i in range(len(digits)):
                if digits[i] != 9:
                    digits[i] += 1
                    break
                else:
                    digits[i] = 0
                    if i+1 >= len(digits):
                        digits.append(1)
            return digits[::-1]
    

Log in to reply
 

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