vault backup: 2022-07-18 15:39:57

This commit is contained in:
Juan 2022-07-18 15:39:57 +08:00
parent 3916a9ea80
commit 9a891515d5

View file

@ -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