Skip to content

Commit 21ea70c

Browse files
authored
Update linkedlist-source-code.md
1 parent 029713f commit 21ea70c

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

docs/java/collection/linkedlist-source-code.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public LinkedList(Collection<? extends E> c) {
9999
`add()` 方法有两个版本:
100100

101101
- `add(E e)`:用于在 `LinkedList` 的尾部插入元素,即将新元素作为链表的最后一个元素,时间复杂度为 O(1)。
102-
- `add(int index, E element)`:用于在指定位置插入元素。这种插入方式需要先移动到指定位置,再修改指定节点的指针完成插入/删除,因此需要移动平均 n/2 个元素,时间复杂度为 O(n)。
102+
- `add(int index, E element)`:用于在指定位置插入元素。这种插入方式需要先移动到指定位置,再修改指定节点的指针完成插入/删除,因此需要移动平均 n/4 个元素,时间复杂度为 O(n)。
103103

104104
```java
105105
// 在链表尾部插入元素

0 commit comments

Comments
 (0)