Lowest Common ancestor of binary tree
ฝัง
- เผยแพร่เมื่อ 19 ก.ย. 2024
- Please consume this content on nados.pepcoding.com for a richer experience. It is necessary to solve the questions while watching videos, nados.pepcoding.com enables that.
NADOS also enables doubt support, career opportunities and contests besides free of charge content for learning. For a better experience and more exercises, VISIT: www.pepcoding....
Have a look at our result: www.pepcoding....
Follow us on our TH-cam page: / pepcoding
Follow us on our FB page: / pepcoding
Follow us on Instagram: / pepcoding
Follow us on LinkedIn: / pepcoding-education
Follow us on Pinterest: / _created
Follow us on Twitter: home
.
.
.
Happy Programming !!! Pep it up 😍🤩
.
.
.
#pepcoding #code #coder #codinglife #programming #coding #java #freeresources #datastrucutres #pepcode #competitive #competitiveprogramming #softwareengineer #engineering #engineer
Great job👍....tree was toughest data structure till the date ....but after watching this series every question is looking so easy and understandable....thank you so much for such great amazing series 😀
Sir g bahut hi achha explain kiya hai...this problem looked like nothing after watching your explanation.
Sir pepcoding ki sari videos bahut achi hoti hai. Keep going
What a series! Thanks!
Kya mast samjhaya sir😁🙏thanks a ton
really good video
Great
Sir, LCA of generic tree ki efficient approaches kara do... Sumit sir ne Level 1 mein node to root path wala method kara rakha hai.
I think this program will also work for 1644. Lowest Common Ancestor of a Binary Tree II right?
Sir please make a video on "binary lifting"
gr8
ok x 100
ok
For better experience, visit nados.io, where you will get well curated content and career opportunities.
This code is giving incorrect answers.
yes why it is
class Solution:
def lowestCommonAncestor(self, root: 'TreeNode', p: 'TreeNode', q: 'TreeNode') -> 'TreeNode':
if not root:
return None
if root.val == p.val or root.val==q.val:
return root
left = self.lowestCommonAncestor(root.left,p,q)
right = self.lowestCommonAncestor(root.right,p,q)
if not left:
return right
if not right:
return left
return root