Leetcode - Delete Node in a BST (Python)

preview_player
Показать описание
August 2020 Leetcode Challenge
Leetcode - Delete Node in a BST

Last problem of month! Thanks for watching!!
Рекомендации по теме
Комментарии
Автор

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

Chewibub
Автор

bro gives a "i have no enemies" kinda vibe, chill af

AnuragNimonkar
Автор

Thank you for explaining all the questions in an easy-to-understand manner!

Автор

Sir, you always give very simple solution to complicated problems.. Thanks

sharifmansuri
Автор

thanks man, i searched this for more than 3 hrs

drakolubez
Автор

this solution is the clearest one I have found

Kyou-by
Автор

"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.

janmichaelaustria
Автор

Thank you so much sir Im learning the simple way from your code

thejasveejaggi
Автор

if you say "do not trust me, I know nothing", what am I supposed to say??

m.y.m
Автор

That was such a great explanation, thanks a mill, Timothy! :)

mukhammadmuratov
Автор

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?

vaishaksid
Автор

Thank You for the explanation. It was pretty helpful !!

jayantdhingra
Автор

this solution is creepy. Much better than the leetcode official one

cyliu
Автор

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

RBTIT
Автор

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...

cici-lxnp
Автор

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

gicuab
Автор

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.

sharifmansuri
welcome to shbcf.ru