class Solution
{
public:
//Function to return the lowest common ancestor in a Binary Tree.
Node* lca(Node* root,int n1,int n2 )
{
if(root==NULL) return NULL;
if(root->data==n1 || root->data==n2) return root;
Node* left=lca(root->left,n1,n2);
Node* right=lca(root->right,n1,n2);
if(left==NULL) return right;
if(right==NULL) return left;
return root;
//Your code here
}
};
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter