From 9a891515d503f69b8a257e13b83ddce0641fdcff Mon Sep 17 00:00:00 2001 From: Juan Date: Mon, 18 Jul 2022 15:39:57 +0800 Subject: [PATCH] vault backup: 2022-07-18 15:39:57 --- OJ notes/pages/Leetcode Reverse-Linked-List.md | 1 + 1 file changed, 1 insertion(+) diff --git a/OJ notes/pages/Leetcode Reverse-Linked-List.md b/OJ notes/pages/Leetcode Reverse-Linked-List.md index 4bd9d75..fca16b8 100644 --- a/OJ notes/pages/Leetcode Reverse-Linked-List.md +++ b/OJ notes/pages/Leetcode Reverse-Linked-List.md @@ -74,6 +74,7 @@ The in place insert is easier to understand, and simple to implement, using a ve > The recursion algorithm takes the advantage of the fact that when you change the node's next properties or nodes after that, the node before still points to the same node, so when every node after **tmp** is reversed, simply move **tmp** after **tmp->next**, which now points to the tail of reversed list > #### Why return the last element of the original list? > It returns the last element in the original list to make sure you are always returning the head of the reversed array, since for any reversed list, the last one comes first. +> **The only recursive part is returning the _tail node_.** ### Solution I've referred to this guy: https://leetcode.com/problems/reverse-linked-list/discuss/58130/C%2B%2B-Iterative-and-Recursive