Update 22. 链表中倒数第 K 个结点.md

题目链接改为力扣中的对应题目,题目描述和代码按该题的接口调整。
This commit is contained in:
CyC2018
2026-10-28 13:45:04 +08:00
parent 616bbadb77
commit ce1603ad31
+11 -11
View File
@@ -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 @@
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/6b504f1f-bf76-4aab-a146-a9c7a58c2029.png" width="500"/> </div><br>
```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;
}
```