LeetCode75-206-Reverse-Linked-List

🧠 思路总结

把每个节点的 next 指向它前一个节点。

原来: 1 → 2 → 3 → 4 → 5 → null
变成: 5 → 4 → 3 → 2 → 1 → null

✅ 代码(Java)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode() {}
* ListNode(int val) { this.val = val; }
* ListNode(int val, ListNode next) { this.val = val; this.next = next; }
* }
*/
class Solution {
public ListNode reverseList(ListNode head) {
ListNode pre = null;
ListNode curr = head;
while (curr != null) {
ListNode next = curr.next;
curr.next = pre;
pre = curr;
curr = next;
}
return pre;
}
}

LeetCode75-206-Reverse-Linked-List
https://powersixxx.github.io/leetcode-blog/2026/02/14/LeetCode75-206-Reverse-Linked-List/
作者
Baowen Liu
发布于
2026年2月14日
许可协议