Can anyone explain why? Python


  • 0
    J
        res = 0
        for i,n in enumerate(stack):
            res += n * (10**(len(stack)-1-i))
        return str(res)
        
    
    
        for n in stack:
            res += str(n)
        return str(int(res))
        
        The above one takes 10x more time than the second one, why? The first one assume stack = list[int], the second one assume stack = list[str]

Log in to reply
 

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