vault backup: 2022-09-20 13:48:08

This commit is contained in:
juan 2022-09-20 13:48:08 +08:00
parent b375b417c1
commit c6b62f472d

View file

@ -80,6 +80,8 @@ I thought a slow O(n ^ 2) hybrid solution, while there are better algorithms, us
#### Fast way:
#### Recursion
The in place insert is easier to understand, and simple to implement, using a very clever trick.
> [!summary] My thoughts on the recursion algorithm
@ -93,6 +95,15 @@ The in place insert is easier to understand, and simple to implement, using a ve
> 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_.**
##### Iteration
The iteration method use two pointers:
- one that points to the new head, as an anchor
- The other one points to nodes we need to iterate over:
### Solution
I've referred to this guy: https://leetcode.com/problems/reverse-linked-list/discuss/58130/C%2B%2B-Iterative-and-Recursive