You are viewing a single comment's thread. Return to all comments →
I think this is much cleaner apporach by arranging v1 < v2
It is much easier to understand the logic.
performance is also slightly better.
you don't need else.. just two if commands and a return
if (...) return left_tree_lca
if (...) return right_tree_lca
return root
Great jobs!! :)
Seems like cookies are disabled on this browser, please enable them to open this website
Binary Search Tree : Lowest Common Ancestor
You are viewing a single comment's thread. Return to all comments →
I think this is much cleaner apporach by arranging v1 < v2
It is much easier to understand the logic.
performance is also slightly better.
you don't need else.. just two if commands and a return
if (...) return left_tree_lca
if (...) return right_tree_lca
return root
Great jobs!! :)