My Java Recursive Solution


  • 2
    Y
    public TreeNode lowestCommonAncestor(TreeNode root, TreeNode A, TreeNode B) {
        if(root.val>A.val && root.val>B.val){
            root = lowestCommonAncestor(root.left, A, B);
        }
        if(root.val<A.val && root.val<B.val){
    	root = lowestCommonAncestor(root.right, A, B);
        }
        return root;
    }

Log in to reply
 

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