Update 0235.二叉搜索树的最近公共祖先.md

可以写的更通俗易懂一些
This commit is contained in:
L1Y1
2022-10-13 17:00:01 +08:00
committed by GitHub
parent adaef1d99b
commit 3947eeaab9

View File

@ -328,13 +328,11 @@ var lowestCommonAncestor = function(root, p, q) {
}
if(root.val>p.val&&root.val>q.val) {
// 向左子树查询
let left = lowestCommonAncestor(root.left,p,q);
return left !== null&&left;
return root.left = lowestCommonAncestor(root.left,p,q);
}
if(root.val<p.val&&root.val<q.val) {
// 向右子树查询
let right = lowestCommonAncestor(root.right,p,q);
return right !== null&&right;
return root.right = lowestCommonAncestor(root.right,p,q);
}
return root;
};