【发布时间】:2021-01-25 17:51:56
【问题描述】:
我认为时间复杂度将是 O(1)。由于 remove 方法的声明中没有循环。如果我考虑时间复杂度的方法不正确,请告诉我。
remove() 的声明:
public synchronized E remove(int index)
{
modCount++;
if (index >= elementCount)
throw new ArrayIndexOutOfBoundsException(index);
E oldValue = elementData(index);
int numMoved = elementCount - index - 1;
if (numMoved > 0)
System.arraycopy(elementData, index+1, elementData, index,
numMoved);
elementData[--elementCount] = null; // Let gc do its work
return oldValue;
}
【问题讨论】:
标签: java data-structures