What is the time complexity of HashMap.containsKey() in java?

后端 未结 4 1289
北荒
北荒 2020-12-02 11:59

I need to know: What is the time complexity of HashMap.containsKey() in java?

4条回答
  •  渐次进展
    2020-12-02 12:43

    Generally O(1), but if we're using a bad hashCode function, we need to add multiple elements to one bucket so it can be O(n) in worst case.

提交回复
热议问题