LeetCode 206: Reverse Linked List RECURSIVELY - Interview Prep Ep 60

preview_player
Показать описание


⭐ Support my channel and connect with me:

LeetCode 206. Reverse Linked List

Reverse a singly linked list.

Example:
Input: [1,2,3,4,5]
Output: [5,4,3,2,1]

Follow up:
A linked list can be reversed either iteratively or recursively. Could you implement both?

Solutions explained (Recursive approach):
1. We'll write a helper function to help us do the recursion which takes the given head node and a newHead node (start with null);
2. Base condition: when head == null, we'll just return newHead;
4. return newHead;

Time: O(n)
Space: O(n)

// TOOLS THAT I USE:

// MY FAVORITE BOOKS:

My ENTIRE Programming Equipment and Computer Science Bookshelf:

And make sure you subscribe to my channel!

Your comments/thoughts/questions/advice will be greatly appreciated!

#softwareengineering #leetcode #algorithms #coding #interview #SDE #SWE #SiliconValley #programming #datastructures
Рекомендации по теме
Комментарии
Автор

Dude you converted the iterative logic to recursive approach like a king. I could easily follow this video

sugandhm
Автор

i have been watching about this problem by lots of youtuber, but they use recursive function in variable instead of "return" made me confused, you have helped me fully understand this problem.

trunguc
Автор

this problem, though easy, is actually quite tricky if you do it the recursive way. I've watched a few other videos where it gives this "if you know you know" vibe without truly explaining why so and how so. This is by far the best and most intuitive way of explaining the recursive solution for this particular question. That being said, for this type of problems, an iterative solution is still easier to understand and yields better space performance.

JimmyCheng
Автор

Honestly, the best solution I've came across. Very simple!

ujjwaljain
Автор

Fisher, your videos are the BEST short and easy to understand. Thank you

wilson
Автор

Great video!! You explained the recursive part so nicely!! Thank you!

gulinatayier
Автор

Love the explanation. Easy to understand.

jasonzeng
Автор

this is brilliant! The normal recursive method is so complex for me. But your is so simple, yet still effective! Thank you!

ngoctungdao
Автор

I love it very easy to understand if you already understand iterative solution. Thank you Fisher Coder for this example.

StayPuft
Автор

Your explanation for recursion is so helpful!

shannonsullivan
Автор

very clear explanation, thank you very much

Veganzza
Автор

Only you make me understand the recursion method!!

Janice-suod
Автор

thank you so much! I was so fuzzy on the recursive method, and thanks to your video I finally get it!

andriy
Автор

Goated video. The helper function makes it similar to the iterative solution and now this way sticks in my mind 😃

vrnkna
Автор

you are awesome man...u are being my Only reason behind my leet code journey...you help me a lot..thank you so much..Love from india

letsleet
Автор

Nice man, other youtube videos just write the recursive answer without really explaining it.

But you can explain it in a simple way

ikrammaududi
Автор

You really have a nice logic, thank u so much <3

ayoubelhioui
Автор

Thank you ! Your explanation is much better than my professor!

oscargong
Автор

Nice explanation, it helped me understand this better, thanks!

thermalmedia
Автор

Awesome solution. very well explained also. thanks

joelgeorge