Another two way in Python 1:42ms (with chinese abacus picture) 2:62ms


  • 0

    1 :42ms  get the idea of abacus ,haha i use chinese abacus to calculator when i was young ,it is real a good way!

    
           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
    2 one lines method ,62ms

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

    @StefanPochmann
    not use lambda ,like this?

    
    [int(x) for x in str(int(''.join(str(x) for x in digits))+1)]
    

  • 0

    lambda x: foo(x) is a pretty complicated way to write foo.


Log in to reply
 

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