Another two way in Python 1:46ms (with picture Chinese abacus) 2:62ms


  • 0

    1: use library directly

    
    return map(lambda x:int(x),str(int(''.join(map(lambda x: str(x),digits)))+1))
    

    62ms
    2: use the define of calculator add , like Chinese Abacus( haha ,I use abacus to calculator when i was young)

    
            plusOne,temp = [],1
            for i in digits[::-1]:
    	        plusOne.append((i+temp)%10)
    	        temp = (i+temp)/10
            if temp ==1 :plusOne.append(temp)
            return plusOne[::-1]
    

    alt text


Log in to reply
 

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