Binary Search Tree : Lowest Common Ancestor

  • + 2 comments

    I like simplicity of your solution. My brain finally has started to figure out (picking up) a pattern in recursion. But the only problem that I am facing as of now is I overcomplicated solution. Such as the one below.

    if((root->data < v2 && root->data > v1)||(root->data > v2&&     root->data < v1)){
        return root;
    }else if(root->data > v1&&root->data > v2){
        return lca(root->left,v1,v2);
    }else if(root->data < v1&&root->data < v2){
        return lca(root->right,v1,v2);
    }else{
        return root;
    }