Binary Search Tree : Lowest Common Ancestor

  • + 3 comments

    Thanks, that was really helpful. This is my C++ Solution

    node * lca(node * root, int v1,int v2)
    {
        node *cur{root};
        for (; cur->data > v1 && cur->data > v2; cur = cur->left);
        for (; cur->data > v1 && cur->data > v2; cur = cur->right);
        return cur;    
    }