Lowest Common Ancestor in a Binary Tree
Given a Binary Tree with all unique values and two nodes value, n1 and n2. The task is to find the lowest common ancestor of the given two nodes. We may assume that either both n1 and n2 are present in the tree or none of them are present.
- Time : O(n)
- Space : O(1)
c++
1 | class Solution { |