Get index of array element faster than O(n)

前端 未结 8 1341
春和景丽
春和景丽 2020-12-07 09:28

Given I have a HUGE array, and a value from it. I want to get index of the value in array. Is there any other way, rather then call Array#index to get it? The p

8条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-07 10:07

    Is there a good reason not to use a hash? Lookups are O(1) vs. O(n) for the array.

提交回复
热议问题