mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 19:44:45 +08:00
更新 0206.翻转链表.md 添加递归解法思路
This commit is contained in:
@ -104,8 +104,10 @@ public:
|
||||
class Solution {
|
||||
public:
|
||||
ListNode* reverseList(ListNode* head) {
|
||||
// 如果链表只有一个节点,返回自身
|
||||
// 边缘条件判断
|
||||
if(head == NULL) return NULL;
|
||||
if (head->next == NULL) return head;
|
||||
|
||||
// 递归调用,翻转第二个节点开始往后的链表
|
||||
ListNode *last = reverseList(head->next);
|
||||
// 翻转头节点与第二个节点的指向
|
||||
|
Reference in New Issue
Block a user