Leetcode - Delete Node in a BST (Python)

  Рет қаралды 15,440

Timothy H Chang

Timothy H Chang

Күн бұрын

Пікірлер: 37
@AnuragNimonkar
@AnuragNimonkar Жыл бұрын
bro gives a "i have no enemies" kinda vibe, chill af
@Chewibub
@Chewibub 8 ай бұрын
Thank you for this video! Conquered a lot of harder lc problems but this one never really “clicked” for me until I heard your explanation
@6014240
@6014240 4 жыл бұрын
Thank you for explaining all the questions in an easy-to-understand manner!
@timc3406
@timc3406 4 жыл бұрын
Glad it was helpful!
@drakolubez6592
@drakolubez6592 4 жыл бұрын
thanks man, i searched this for more than 3 hrs
@sharifmansuri607
@sharifmansuri607 4 жыл бұрын
Sir, you always give very simple solution to complicated problems.. Thanks
@timc3406
@timc3406 4 жыл бұрын
So nice of you! Thank you :)
@janmichaelaustria620
@janmichaelaustria620 4 жыл бұрын
"Do not trust me, I know nothing". Man, I'm sure gonna miss that bro. Way to finish off the month strong. Tim, your videos have helped so much. I think on the really hard problems I'd look at some of the solutions on leetcode, but then after watching you videos, it all just clicks. I hope you kill it over in SF! Hopefully our paths will cross some day.
@timc3406
@timc3406 4 жыл бұрын
Lol I'll still solve problems whenever I find the time, it's something I enjoy and need to continue to work on anyway Definitely hope our paths cross!
@Kyou505-b1y
@Kyou505-b1y 3 ай бұрын
this solution is the clearest one I have found
@m.y.m401
@m.y.m401 Жыл бұрын
if you say "do not trust me, I know nothing", what am I supposed to say??
@vaishaksid7594
@vaishaksid7594 2 жыл бұрын
Why do we set root.left = delete(root.left, key), Why are we setting this to equal to the return value? What's the purpose?
@mukhammadmuratov5715
@mukhammadmuratov5715 2 жыл бұрын
That was such a great explanation, thanks a mill, Timothy! :)
@cyliu2434
@cyliu2434 2 жыл бұрын
this solution is creepy. Much better than the leetcode official one
@thejasveejaggi6213
@thejasveejaggi6213 4 жыл бұрын
Thank you so much sir Im learning the simple way from your code
@leroyjameshopkins5164
@leroyjameshopkins5164 Жыл бұрын
Damn, such an elegant solution.
@RBTIT
@RBTIT 3 жыл бұрын
Root.left= self.deleteNode(root.right,root.val) And If not root.right and root.left : root.left .. In above lines is root.left is same
@timc3406
@timc3406 3 жыл бұрын
I think so?
@jayantdhingra6
@jayantdhingra6 3 жыл бұрын
Thank You for the explanation. It was pretty helpful !!
@touwmer
@touwmer 2 жыл бұрын
Thanks, great solution!
@gicu8ab2
@gicu8ab2 2 жыл бұрын
I think if you replace lines 18-20 with the following lines the code is a little cleaner and easier to understand: while ptr.left: prev = ptr ptr = ptr.left node.val = ptr.val prev.left = None
@lonnleaf
@lonnleaf Жыл бұрын
And you introduce a bug, as your code do not work for case where there is no left, additional condition required for your code to work. And when there is recursion everywhere anyway no point to modify code to exclude it, especially it was one line instead of several lines and condition, IMHO.
@tarasrogulya4213
@tarasrogulya4213 2 жыл бұрын
Thanks whene you explain its easy
@mustaqode_6617
@mustaqode_6617 8 ай бұрын
Thanks a ton.
@cici-lx6np
@cici-lx6np 2 жыл бұрын
I cannot pass the test case with the original code. It works after I change this: ------------- if not root.left and not root.left: return None if not root.left and root.right: return root.right if root.left and not root.right: return root.left ------------- to this: ------------- if not root.right: return root.left if not root.left: return root.right ------------- I don't know the reason tho...
@tonyhe001
@tonyhe001 3 жыл бұрын
Thanks, very clear
@nagendrabommireddi8437
@nagendrabommireddi8437 2 жыл бұрын
thanks a lot sir
@sharifmansuri607
@sharifmansuri607 4 жыл бұрын
Sir this code doesn't work on edge case like 100 / 70 \80 100 is root, 70 is it's left child and 80 is right child of 70. And if we try to delete 100. As it doesn't enters the recursion that is why happens.
@timc3406
@timc3406 4 жыл бұрын
It's totally possible I missed something, let me know if you find a fix
@sharifmansuri607
@sharifmansuri607 4 жыл бұрын
@@timc3406 yes I did find a fix for this.
@olanmalde9312
@olanmalde9312 4 жыл бұрын
@@sharifmansuri607 , what was the fix?
@MWackodj888
@MWackodj888 4 жыл бұрын
@@sharifmansuri607 What did you do?
@sharifmansuri607
@sharifmansuri607 4 жыл бұрын
@@MWackodj888 hi kindly find code below please take care of indentation def delete(self,node,val): if node is None: return def preorder_precedor(node): node=node.left while node.right: node=node.right return node.data def preorder_succsor(node): node=node.right while node.left: node=node.left return node .data if valnode.data: if node.right: node.right=self.delete(node.right,val) else: if node.left==None and node.right==None: node=None elif node.left: node.data=preorder_precedor(node) node.left=self.delete(node.left,node.data) else: node.data=preorder_succsor(node) node.right=self.delete(node.right,node.data) return node
@charantechgeek
@charantechgeek 2 жыл бұрын
great explanation, loved it.
Delete Node in a BST - Leetcode 450 - Python
12:59
NeetCodeIO
Рет қаралды 53 М.
Delete a node from Binary Search Tree
18:27
mycodeschool
Рет қаралды 1,2 МЛН
小丑教训坏蛋 #小丑 #天使 #shorts
00:49
好人小丑
Рет қаралды 54 МЛН
The Best Band 😅 #toshleh #viralshort
00:11
Toshleh
Рет қаралды 22 МЛН
小丑女COCO的审判。#天使 #小丑 #超人不会飞
00:53
超人不会飞
Рет қаралды 16 МЛН
So You've Been Rejected from FAANG
5:56
Timothy H Chang
Рет қаралды 9 М.
Leetcode - Longest Palindromic Substring (Python)
7:36
Timothy H Chang
Рет қаралды 17 М.
Binary Search Tree Removal
14:10
WilliamFiset
Рет қаралды 48 М.
How to solve (almost) any binary tree coding problem
4:20
Inside code
Рет қаралды 202 М.
Python Data Structures #5: Binary Search Tree (BST)
31:54
Brian Faure
Рет қаралды 170 М.
Binary Search Tree (BST): Deletion Function
6:39
Brian Faure
Рет қаралды 24 М.
小丑教训坏蛋 #小丑 #天使 #shorts
00:49
好人小丑
Рет қаралды 54 МЛН