Javascript Solution with Video link


  • 0

    Check this video for LCA in binary search tree
    https://www.youtube.com/watch?v=TIoCCStdiFo

    var lowestCommonAncestor = function(root, p, q) {
        if (root.val < p.val && root.val < q.val) {
            return lowestCommonAncestor(root.right, p, q);
        }  else if (root.val > p.val && root.val > q.val) {
            return lowestCommonAncestor(root.left, p, q);
        }
        return root;
    };

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.