Update 24. 反转链表.md

题目链接改为力扣中的对应题目,题目描述和代码按该题的接口调整。
This commit is contained in:
CyC2018
2026-10-28 13:45:04 +08:00
parent 8a47dbbb95
commit f5fae6e5c2
+4 -4
View File
@@ -1,18 +1,18 @@
# 24. 反转链表
[NowCoder](https://www.nowcoder.com/practice/75e878df47f24fdc9dc3e400ec6058ca?tpId=13&tqId=11168&tPage=1&rp=1&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking&from=cyc_github)
[Leetcode](https://leetcode.cn/problems/fan-zhuan-lian-biao-lcof/)
## 解题思路
### 递归
```java
public ListNode ReverseList(ListNode head) {
public ListNode trainningPlan(ListNode head) {
if (head == null || head.next == null)
return head;
ListNode next = head.next;
head.next = null;
ListNode newHead = ReverseList(next);
ListNode newHead = trainningPlan(next);
next.next = head;
return newHead;
}
@@ -23,7 +23,7 @@ public ListNode ReverseList(ListNode head) {
使用头插法。
```java
public ListNode ReverseList(ListNode head) {
public ListNode trainningPlan(ListNode head) {
ListNode newList = new ListNode(-1);
while (head != null) {
ListNode next = head.next;