LeetCode #21: Merge Two Sorted Lists (Visualization)

preview_player
Показать описание
A step-by-step solution to #LeetCode question 21: Merge Two Sorted (Linked) Lists
0:00 Intro
0:15 Code Walkthrough
2:38 Shorthand "OR" explanation

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

Takes a lot of effort to explain a complex problem in a clear way. This was super clear and easy to understand. Thank you!

govindrai
Автор

Great explanation! I usually don't comment on YouTube videos but this is the first video explaining the problem that actually made it easy for me to understand. Thanks!

ytrg
Автор

Your videos always make me smile, thank you for brightening my day!

MyCodingDiary
Автор

Well explained! I always like your video!

andygo
Автор

That was awesome, as this was my first time solving any linked list problem so this diagrammatical representation of every line made my concept crystal clear. Thank you!!

proteansan
Автор

thank you! a simple and intuitive explanation.

guna
Автор

Algo Engine slaying another leetcode problem. Thank you for explaining concepts clearly, something our professor can't do.

youtubeweb
Автор

спасибо за помощь, очень классное видео

мишаиосько
Автор

you're the goat, keep up these videos

RANDOMGUYPRODUCTIONSS
Автор

I'm confused about node.

1. head = ListNode()
current = head # does this mean current = ListNode()?
head and current should look like this?
head [0, None]
current [0, None]

2. if list1.val < list2.val:
current.next = list1 # does this mean head.next = list1 too?
list1 = list1.next
then head [0, 1], current [0, 1]?

3. then the next iteration they will look like this right?
head [0, 1] -> [1, 2]
current [1, 2]
why current aren't the same as head anymore I thought any change made to current would apply to head too.

exab
Автор

My issue is with “current = head”, doesn’t that mean a current is a new variable that contains the same thing as head? How is it now a pointer that when manipulated, it now also affects the head? It doesn’t make sense why you return head.next, when all the pointer manipulation has been done to current, or is there a way linked lists work that I am not aware of? Nice video btw

dnm
Автор

Hey! Thank you for your video. I liked it! I have one question (or two).
In the video, when current is moving, you show that the old arrow from list1 or list2 changes its position towards current. But it doesn't really go away, right? Or do we change the original list1 and list2, and unused arrows (refs) are deleted by garbage collector?

syuo
Автор

Make more vids on stack, queues, trees, graphs QS.

SimranMallar
Автор

Please complete the entire Blind 75 series.

ameyaraj
Автор

list1 = [1, 2, 4]
list2 = [1, 3, 4]
class s:
def mergeTwoLists(self, list1, list2):
l= list1 + list2
l.sort()
return l
a=s()
a.mergeTwoLists(list1, list2)

abhi-btwj
Автор

I am a code self-learning beginner. Sorry for asking stupid questions.

I am pleased to ask that
1. why we can type'' list1.val'' without setting ''variable = ListNode()''?
2. why ''list1.val'' is pointing to the first interger in list1 instead of the hole list?

chichungwan
Автор

Hi, great video! Is it assumed that in these types of problems you are allowed to reference nodes from the input lists instead of creating new ones? My concern is that if someone in the future mutates one of the inputs it will also mutate the merged list

Роман-дьц
Автор

thank you for explanation! by the way how does the actual input looks like? when I try to call function using list1 and list2 (providing as a list) it throws error I suppose this is not the way to input lists (or arrays whatever) but leetcode gives the impression as if they give as a list. like this:

Input
list1 =
[1, 2, 4]
list2 =
[1, 3, 4]
Output
[1, 1, 2, 3, 4, 4]
Expected
[1, 1, 2, 3, 4, 4]

Автор

why do we do current.next = list1/list2 instead of current = list1/list2?

jeffreyalidochair
Автор

Very nice video! Thanks for sharing! One question. Shouldn't the value of head node be 0 instead of None?

alimehdizadeh