LeetCode Merge Two Sorted Lists Solution Explained - Java

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


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

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

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

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

For anyone wondering, a linked list is a pointer data structure. This means that when we say “node.next = l1” it is a reference to a pointer which holds the full data. As such the old “next” pointer remains as well as the value. So at the very end we are truly appending the “rest” of the non null list not just a value without a next pointer (it so happens that lines 31&36 are useless)

stevothebeavo
Автор

Those who are submitting for the first time and getting an extra 0 in front of the list, its because you are returning the address of an empty node, whereas the first element is being stored in the next node to the head node. Try returning temp_node->next

siddhantsingh
Автор

3:45 "First try!"
sees attempts. :o

On a serious note, this is really helpful. Thank you so much for posting this, please keep it up!

theducksneezes
Автор

Im a third year CS student and even the easy leetcode problems make no sense to me usually. I can tell I still don't have that fundamental base yet. There is a certain level of assumed knowledge this video is going with. Oh well, I will get there : _ )

headyshotta
Автор

awesome video. One issue though is on line #31 l1=l1.next and #36 l2=l2.next seems unnecessary

jeffery
Автор

I wish i could see more of the editor rather than your face.

vruttantbalde
Автор

thanks, nick for posting this, one suggestion front camera screen is blocking the end part of the code.

akware
Автор

nick is so legend even my sister know him whenever she swing by my pc she's like hey thats NICK WHITE

GameFlife
Автор

Hi. I know about reference types (in Java or C#) but I don't understand how `head` get its value. what topics should I read about to know how its works?

rezayegane
Автор

Would be much nicer if your photo wasn't covering up the code :(

e.g.
Автор

What if after one of the lists reaches null, the other list has more than one node left in it? For example if the lists were [1, 2, 3, 4] and [5, 6, 7, 8] by the time the first node reaches null the second list would still have 4 more nodes to go through since all the values were larger than the larger value in the first list. With the if statements he added at the end, his program would just pull the first node off the second list and possibly leave more remaining. Wouldn't you want to implement a while loop to go through the remaining list until it reaches null?

sankalppatil
Автор

Nick, it's a very good explanation, but your face covers part of the code.

davidfield
Автор

Why we are just appending one last node in the final. What if we have 2 link list with 3 and 5 nodes. After while loop we need to append 2 items in the the final list from l2.

divyabharti
Автор

How is temp_node being updated as curr updates during the traversal?

SombaKalen
Автор

why we return temp_node insteadof curr ???? why???

jasmeenkaur
Автор

Very great ! Could you please explain the l1!=null part please I dont get why we really use it?

abiramivadivel
Автор

I was trying this problem by sorting inplace. Without creating new list. Was stuck for so many hours 😅

pratikwadekar
Автор

I don't understand why you wrote the line 26 code.

vickyk
Автор

Shouldn't it be, l1.val <= l2.val ??

ashutoshwalimbe
Автор

I was told on the interview that I cannot create a new list and this problem got me stumped.

lostmeme
join shbcf.ru