mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 19:44:45 +08:00
Update 0235.二叉搜索树的最近公共祖先.md
可以写的更通俗易懂一些
This commit is contained in:
@ -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;
|
||||
};
|
||||
|
Reference in New Issue
Block a user