java单链表版本中,因为有虚拟头节点,所以不用对Index=0的情况进行特殊处理

This commit is contained in:
wutao
2024-06-20 16:44:42 -04:00
parent 843c3f7fa0
commit 0e068f95f2

View File

@ -365,10 +365,7 @@ class MyLinkedList {
return;
}
size--;
if (index == 0) {
head = head.next;
return;
}
//因为有虚拟头节点所以不用对Index=0的情况进行特殊处理
ListNode pred = head;
for (int i = 0; i < index ; i++) {
pred = pred.next;