From ce1603ad3139a760fc80c6612a4f8e9b00de5cf1 Mon Sep 17 00:00:00 2001 From: CyC2018 Date: Wed, 28 Oct 2026 13:45:04 +0800 Subject: [PATCH] =?UTF-8?q?Update=2022.=20=E9=93=BE=E8=A1=A8=E4=B8=AD?= =?UTF-8?q?=E5=80=92=E6=95=B0=E7=AC=AC=20K=20=E4=B8=AA=E7=BB=93=E7=82=B9.m?= =?UTF-8?q?d?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 题目链接改为力扣中的对应题目,题目描述和代码按该题的接口调整。 --- notes/22. 链表中倒数第 K 个结点.md | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/notes/22. 链表中倒数第 K 个结点.md b/notes/22. 链表中倒数第 K 个结点.md index aa00d274..354256d7 100644 --- a/notes/22. 链表中倒数第 K 个结点.md +++ b/notes/22. 链表中倒数第 K 个结点.md @@ -1,6 +1,6 @@ # 22. 链表中倒数第 K 个结点 -[牛客网](https://www.nowcoder.com/practice/886370fe658f41b498d40fb34ae76ff9?tpId=13&tqId=11167&tab=answerKey&from=cyc_github) +[Leetcode](https://leetcode.cn/problems/lian-biao-zhong-dao-shu-di-kge-jie-dian-lcof/) ## 解题思路 @@ -9,19 +9,19 @@

```java -public ListNode FindKthToTail(ListNode head, int k) { +public ListNode trainingPlan(ListNode head, int cnt) { if (head == null) return null; - ListNode P1 = head; - while (P1 != null && k-- > 0) - P1 = P1.next; - if (k > 0) + ListNode p1 = head; + while (p1 != null && cnt-- > 0) + p1 = p1.next; + if (cnt > 0) return null; - ListNode P2 = head; - while (P1 != null) { - P1 = P1.next; - P2 = P2.next; + ListNode p2 = head; + while (p1 != null) { + p1 = p1.next; + p2 = p2.next; } - return P2; + return p2; } ```