gpt4 book ai didi

java - 对象 ArrayList 中 contains(Object o) 的时间复杂度

转载 作者:IT老高 更新时间:2023-10-28 20:55:28 25 4
gpt4 key购买 nike

正如标题所说,我想知道 contains() 的时间复杂度是多少ArrayList 的方法是。

最佳答案

O(n)

The size, isEmpty, get, set, iterator, and listIterator operations run in constant time. The add operation runs in amortized constant time, that is, adding n elements requires O(n) time. All of the other operations run in linear time (roughly speaking). The constant factor is low compared to that for the LinkedList implementation.

http://download.oracle.com/javase/6/docs/api/java/util/ArrayList.html

关于java - 对象 ArrayList 中 contains(Object o) 的时间复杂度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5771740/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com