LOWEST COMMON ANCESTOR OF A BINARY TREE II | PYTHON | LEETCODE 1644
HTML-код
- Опубликовано: 24 фев 2022
- In this video we are solving Lowest Common Ancestor of a Binary Tree II. This is an interesting problem because it's basically a carbon copy of the first iteration of this problem except this time we are not guaranteed to have the nodes P and Q exist in the tree.
Wow, the explanation was super clear! Thx, mate!
Thanks! Make sure to subscribe if you haven’t already 😉
Within in the first 3 minutes of your video I figured out why my code wasn't working. Once I did a check for P and for Q separately first to confirm they both exist, my solution started working.
All I had to do is check if P or Q doesn't exist and return Null, if they both exist, then I can do the normal "find ancestor" code.
But of course this wasn't efficient enough, so thank you for showing me the optimized version
Thank you . Your channel videos are super easy to understand.
Great Explanation! Thanks!
Glad you enjoyed the video! Make sure to subscribe so you don’t miss future videos
Thank you for explaining, it was helpful!
Glad you found the video helpful! Make sure to subscribe so you don’t miss other videos coming soon
Wouldn't storing l and r result in an O(N) space complexity? Since the None value also takes space in memory as well.
8:59 sorry I am confused here. If returning 4 or 5 doesn't matter, how would the algorithm make sure to return the correct answer, 5 but not 4?