LeetCode Palindrome Linked List Solution Explained - Java

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


Preparing For Your Coding Interviews? Use These Resources
————————————————————

Other Social Media
----------------------------------------------

Show Support
------------------------------------------------------------------------------

#coding #programming #softwareengineering
Рекомендации по теме
Комментарии
Автор

Maybe you can put the camera window to the right top corner? It blocked the code.

ssdoesntlie
Автор

Odd-numbered items example

Say the original list is 12321.
After iterating through slow and fast: Slow -> 321
After reversing slow: Slow -> 123
Reset fast to head
However, note that the state of the original list is now: fast->1->2->3<-2<-1-<slow
This is where it might be confusing. Note that the original list IS NOT 1->2->1->2->3 BUT 1->2->3<-2<-1.
Now, regardless of even/odd items in original list, iterating one-by-one over slow and fast will never overflow. For an even-numbered items' list (e.g. 123321), the situation now would be 1->2->3->3<-2<-1.

Hope that helps.

tgroy
Автор

0:01, that slapping which every Nick White video starts with.

sadmanabedin
Автор

My Goal for this year is to solve all the leetcode problems you have done here. Your channel is the first place I refer to if i am stuck solving LC.

theSDE
Автор

I have been watching a lot of the videos that you posted on solving leetcode problems, cuz i have no idea how to do a lot of them on my own, lol. Just want to say thank you for spending the time to make these videos and posting them on youtube, it really helps!!!

kevindai
Автор

We can also make a copy of the original list, reverse the list and then compare the original list and the reverse list using a loop ..

SudeepDasguptaiginition
Автор

Great Man! You are literally helping the community a lot. Keep it up!

gautamarora
Автор

great explain .. keep up the good content ..
I think you should also put a pointer to the camera window and iterate it to the left corner

mohammedfalih
Автор

Thanks for this tutorial, i just didnt understand why you needed to go to half of the array. But once you reverse it, it all makes sense.

garrett-ohara
Автор

When there is a odd length linked list, we should not compare the middle element with anything. For ex: 11211 is a palindrome and the value "2" which is a middle element shouldn't be a part of the comparison logic. This logic needs to be added here.

ramyamurthy
Автор

Thanks for covering most of the code with your image 🙂

srinimurthy
Автор

Note: Use first while loop to calculate slow and fast nodes. After the loop is complete, slow will be at mid point, at that point, reverse the list from mid point. Set fast to head and compare two lists. Compare the two linked lists using another while loop.

smithcodes
Автор

Thank you Nick!! Really good explanation!!

vitalijdao
Автор

Hey you explained it really nice could you load more problems.

anushkadhar
Автор

very good stuff Nick, this is extremely helpful. and dont worry none of us CS guys are good at explaining, you're doing good.

marcbatete
Автор

nice one!! but, try to provide the source code as you're window always blocks the screen

Salesforce_Nexus
Автор

For those who cant see last function :)
public ListNode reversed(ListNode head)

sharathm
Автор

wow, this solution is so genius. Algorithms are fun

saidharshanshan
Автор

suggestion-> YOU CAN USE WHITEBOARD TO EXPALINA ND THEN CODE

atharvakulkarni
Автор

i am finding this problem really difficult. Though i see it listed as Easy in leetcode :(

okey