Merge Two Sorted Lists | Leet code 21 | Theory explained + Python code

  Рет қаралды 10,923

Sai Anish Malla

Sai Anish Malla

Күн бұрын

Пікірлер: 34
@eshw23
@eshw23 Жыл бұрын
This earned a subscriber, ive been really struggling with this problem, appreciate your effort.
@anasbhih5114
@anasbhih5114 9 ай бұрын
Thank you so much! i finally found a well explained video
@MohammedAhmedIsAwesome
@MohammedAhmedIsAwesome 2 жыл бұрын
Fantastic explanation, thank you!!
@tabmax22
@tabmax22 2 жыл бұрын
I don't understand the cur = dummy business. At the end when you print dummy, why does that not print cur?
@sanjaykj4818
@sanjaykj4818 Жыл бұрын
Thanks man appreciate your effort
@ayeshaarifkhawaja-nz4xt
@ayeshaarifkhawaja-nz4xt Жыл бұрын
Awesome explanation, thank you
@rouzbehtalebi
@rouzbehtalebi Жыл бұрын
Nice Explanation 👍
@cecepskj6948
@cecepskj6948 Жыл бұрын
how did the program know that we only took the first initial value of l1 or l2? why don't we just code like this: curr.next = l2.val ?? Ty in advance
@manpt123
@manpt123 2 жыл бұрын
what a explanation bro. sub done. carry on
@tigerior
@tigerior 3 жыл бұрын
Cool stuff! Thank you!
@viktorsk8202
@viktorsk8202 2 жыл бұрын
Thanks bro, you so kind!
@srikumarma
@srikumarma Жыл бұрын
Hey, thx for the explanation but in leetcode when i run the code i am getting run time limit exceeded
@sumeyyesalman4719
@sumeyyesalman4719 3 жыл бұрын
Thank you, a very nice explanation!
@eugenioforever3677
@eugenioforever3677 2 жыл бұрын
I have not found a video that explains line 6 and 7 of the code.
@Fetdude
@Fetdude 2 жыл бұрын
I have a question: How do I print the linked list that dummy.next produces? Ty in advance
@imbesrs
@imbesrs 2 жыл бұрын
You'd have to iterate over the entire linked list. Its the one downside of linked list. class node: def __init__(self, data=None): self.data = data self.next = None def display(self): elems = [ ] cur_node = self while cur_node.next != None: cur_node = cur_node.next elems.append(cur_node.data) print(elems) This method you add them all to an array and print the array. You could also do string concatenation or print at the end of each while loop iteration
@Fetdude
@Fetdude 2 жыл бұрын
@@imbesrs you sound like a stackoverflow hero
@imbesrs
@imbesrs 2 жыл бұрын
@@Fetdude I appreciate that but im very new to coding as well. Just now learning about linked list so the knowledge wsa fresh in my head. Cheers!
@neerajkumar81
@neerajkumar81 2 жыл бұрын
@@imbesrs `elems` here is a flat list, the problem needs a linked list to be output. Meaning, you need to manage the next pointers appropriately in the final result.
@imbesrs
@imbesrs 2 жыл бұрын
@@neerajkumar81 The person I replied to wanted to know how to print the output. I was not answering the original leetcode question
@afsharali1279
@afsharali1279 Жыл бұрын
For me with the same code, Test case1 failed
@parthshah1563
@parthshah1563 3 жыл бұрын
I have one question:- Initially the Dummy node is pointing to the head node (I got it) but which head node? Head node of L1 or head node of L2?
@AbhishekSharma-vb9ux
@AbhishekSharma-vb9ux 2 жыл бұрын
I think dummy node is an independent node with val=0 and next = none. It doesnt point to any head initially, and after the first comparison, it points to '1'.
@shashankl8589
@shashankl8589 2 жыл бұрын
initially dummynode is pointing to None,then with the condition it will point to head of l1 or l2
@HarshPatel-iy5qe
@HarshPatel-iy5qe 10 ай бұрын
Consider dummy node is pointing to output linked-list
@Rustincohle88
@Rustincohle88 Жыл бұрын
Why ListNode() is used in Sol
@ishayadav001
@ishayadav001 3 жыл бұрын
👏🏽👏🏽👏🏽
@tanishasethi7363
@tanishasethi7363 3 жыл бұрын
Tysm 😭
@ahmedanwer6899
@ahmedanwer6899 2 жыл бұрын
pulling my hair because of this why does the following for the while loop part not work? why do i need the else statement? while list1 and list2: if list1.val > list2.val: print(list2.val) tail.next = list2 list2 = list2.next if list1.val
@maamounhajnajeeb209
@maamounhajnajeeb209 2 жыл бұрын
youshould put (if then elif) not (two if)
@mahir7530
@mahir7530 3 жыл бұрын
why do we return dummy?
@ngochainguyen91
@ngochainguyen91 2 жыл бұрын
same Question :))
@neerajkumar81
@neerajkumar81 2 жыл бұрын
Initially dummy points to curr. But, later in the loop - curr moved on to create the resultant list. Finally, dummy still points to an address which was held by curr at the very beginning. So, while returning dummy, we are making sure, dummy gets the head pointer of the resultant list.
@chandraprakash934
@chandraprakash934 Жыл бұрын
@@neerajkumar81 thanks for explaining :)
Merge Sorted Array | Leet code 88 | Theory explained + Python code
16:12
Merge Two Sorted Lists - Leetcode 21 - Linked Lists (Python)
9:41
How Much Tape To Stop A Lamborghini?
00:15
MrBeast
Рет қаралды 235 МЛН
А я думаю что за звук такой знакомый? 😂😂😂
00:15
Денис Кукояка
Рет қаралды 4,7 МЛН
This Game Is Wild...
00:19
MrBeast
Рет қаралды 186 МЛН
Add Two Numbers | Leet code 2 | Theory explained + Python code
16:07
Sai Anish Malla
Рет қаралды 5 М.
Coding Interview Question - Merge Two Sorted Lists (LeetCode)
8:57
AlgosWithMichael
Рет қаралды 6 М.
Next Permutation | Leet code 31 | Theory explained + Python code
19:19
Sai Anish Malla
Рет қаралды 15 М.
Linked List - Data Structures & Algorithms Tutorials in Python #4
28:16
Arrays in Python: Two Sum Problem
14:05
LucidProgramming
Рет қаралды 32 М.
Permutations | Leet code 46 | Theory explained + Python code
11:58
Sai Anish Malla
Рет қаралды 20 М.
Merge Two Sorted Lists - Leetcode 21 - Python
6:16
NeetCode
Рет қаралды 390 М.