Set vs Array , difference

前端 未结 3 1578
情书的邮戳
情书的邮戳 2020-12-16 11:06

What is the difference between Set and Array in Ruby except for the fact that sets keep unique elements while arrays can keep duplicate elements?

3条回答
  •  春和景丽
    2020-12-16 11:40

    For me the main difference is that Sets are implemented as hashes, so you have O(1) membership tests for elements.

提交回复
热议问题