We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Binary Search Tree : Lowest Common Ancestor
Binary Search Tree : Lowest Common Ancestor
Sort by
recency
|
768 Discussions
|
Please Login in order to post a comment
python code:
def lca(root, v1, v2):
if root.info > v1 and root.info > v2:
elif root.info < v1 and root.info < v2:
else: return root
C++ `14 Solution:
How frist image can be a BST? The left child (4) is greater than its parent node (3), which violates the Binary Search Tree property. Do I missing something?
My Java 8 Solution
There's no set up code for doing this in Kotlin, so I wrote some. If you use this, you just need to create 'fun findLowestCommonAncestor(v1: Int, v2: Int, root: Node): Int'