very easy python sol. in 34ms 直觀寫法

  • 0

    just think it as a digit counter
    In case of overflow, Add a zero to the last.

    digits = digits[::-1] + [0]
            digits[0] += 1
            for i in range(len(digits)):
                if digits[i] == 10:
                    digits[i] = 0
                    digits[i+1] += 1
            if digits[-1]==1:
                return digits[::-1]
            else : 
                return digits[::-1][1:]

Log in to reply

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