mirror of
https://github.com/CyC2018/Interview-Notebook.git
synced 2026-10-30 07:33:45 +00:00
Update 24. 反转链表.md
题目链接改为力扣中的对应题目,题目描述和代码按该题的接口调整。
This commit is contained in:
+4
-4
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user