28. Lowest Common Ancestor in a BST
My Approach
Time and Auxiliary Space Complexity
Code (C++)
class Solution{
public:
Node* LCA(Node *root, int n1, int n2)
{
int curr = root->data;
if(curr > n1 && curr > n2)
return LCA(root->left, n1, n2);
if(curr < n1 && curr < n2)
return LCA(root->right, n1, n2);
return root;
}
};Contribution and Support
Last updated