What is time complexity of a list to set conversion?

前端 未结 1 1231
隐瞒了意图╮
隐瞒了意图╮ 2020-12-01 13:29

I\'ve noticed the table of the time complexity of set operations on the python official website. But i just wanna ask what\'s the time complexity of converting a list to a s

1条回答
  •  天涯浪人
    2020-12-01 13:59

    Yes. Iterating over a list is O(n) and adding each element to the hash set is O(1), so the total operation is O(n).

    0 讨论(0)
提交回复
热议问题