Runtime: 7 ms, beats 96.83 % of java submissions

  • 0
    public class Solution {
    	public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {
    		if (root.val < Math.min(p.val, q.val))
    			root = lowestCommonAncestor(root.right, p, q);
    		else if (root.val > Math.max(p.val, q.val))
    			root = 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.