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; } ```