Why copying the temporary list doesn't hurt performance in Python?


  • 0
    Z

    I've read many solutions in different languages. Many of the DFS-based Python solutions copies the temporary list in every DFS call by simply passing through 'tmp + cand[i]' as an argument. This makes the code very clean, because we can add the tmp directly to the result set without copying it,but it looks very expensive: one list copy for each DFS call does't sound good

    However, it runs very fast in reality. I am wondering why the numerous list copies don't hurt performance


Log in to reply
 

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