4 lines Python code with O(n)

  • 0

    # Idea: invert array to 'int', then invert the 'int' type to the array after add one.
    def plusOne(self, digits):
    strnum = ''
    for i in xrange(len(digits)):
    strnum += str(digits[i])
    return [x for x in str(int(strnum) + 1)]

Log in to reply

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