LeetCode 160. Intersection of Two Linked Lists Solution Explained - Java

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


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

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

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

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

LOL! Somebody kill me first. THIS guy's thought process is amazing.

abhishekkumargupta
Автор

We have 1000 of problems in life, but solving leetcode problem isn't one of them, thanks to Nick

Rahulyadav-lvdh
Автор

Another approach is to count elements in A and B. And then find out the diff. Move the pointer forward in longer list for diff number of times. Now, we have same number of end elements to compare. Then start comparing values iterating through both lists.

oscaropdyou
Автор

You are the Boss Nick !!
Some ideas / explanations/ approaches of yours are "Superior" to that of Kevin !!

raam
Автор

Any tips how can you come up with these solutions?

aivancarlostuquero
Автор

I wouldve never thought of that. Wtf i feel so stupid.

hacker-
Автор

What about on the Example 3 No intersection. a_pointer forever loop of linked-list B. Does the linked-list A ->null = linked-list B -> null? Are those "null" from different linked-list equal?

deewademai
Автор

Wont this give an infinite loop as the pointers keep jumping from one list to another if there is no intersection?

bismeetsingh
Автор

Thank you so much Nick for your efforts. It helps people like me :)

monikajha
Автор

just a doubt: When both lists have no intersection than will it return NULL or be stuck inside a while loop?

sarthakbhatia
Автор

For example one I think lists intersect at 1 first and then at 8. I don’t know why EVERYONE is ignoring this thing? Am I missing something here? Please help.

tushardudhatra
Автор

My goodness, how and when will I start to come up with such solutions! I mean how the hell to think for such an approach man..!!

yudhisthirsingh
Автор

Amazing but I just don't understand why it works!

yitingg
Автор

Wow thanks! I would've never thought of doing it this way.

josephlee
Автор

Why the 1st example 1st intersectVal is not 1 but 8? both linked list the 1 -> 8 -> 4 -> 5

kennethso
Автор

I want to understand when there is a difference in the no of elements of two linkedlists, how does the line 22 & 28 works. Can someone explain?

himanshibaranwal
Автор

Can someone explain why this works even if they are parallel? Is that because both will eventually end up with null and they are equal and would be returned as null?

victoriac
Автор

I understand how it works... but I don't understand why it works. help?

keokawasaki
Автор

Just to want to know. Do you come up this idea by yourself in the beginning? It's amazing! @Nick

michaelyao
Автор

how will this logic work if two linkedlist are not intersecting? The while loop will keep on running without intersection.

noormaaz