My java solution to share


  • 15
    M

    public class Solution {

    public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {
        if(p.val>q.val)
            return lowestCommonAncestor(root, q,p);
        if(root.val>= p.val && root.val<=q.val)
            return root;
        return lowestCommonAncestor(root.val>p.val?root.left:root.right, p,q);    
    }
    

    }


Log in to reply
 

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