Skip to content

Commit 9231686

Browse files
authored
Update 09. 删除链表的倒数第 N 个结点.md
1 parent 1332b7f commit 9231686

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

09. 删除链表的倒数第 N 个结点.md

+3-4
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,14 @@ class Solution:
3636
def removeNthFromEnd(self, head: ListNode, n: int) -> ListNode:
3737
#借助快慢指针,找到要删除节点的前驱节点
3838
dummy = ListNode(0, head)
39-
second = dummy
40-
first = head
39+
second = first = dummy
4140
42-
for i in range(n):
41+
for i in range(n+1):
4342
first = first.next
4443
4544
while first:
4645
first = first.next
4746
second = second.next
4847
second.next = second.next.next
4948
return dummy.next
50-
```
49+
```

0 commit comments

Comments
 (0)