parent
adaef1d99b
commit
3947eeaab9
|
|
@ -328,13 +328,11 @@ var lowestCommonAncestor = function(root, p, q) {
|
||||||
}
|
}
|
||||||
if(root.val>p.val&&root.val>q.val) {
|
if(root.val>p.val&&root.val>q.val) {
|
||||||
// 向左子树查询
|
// 向左子树查询
|
||||||
let left = lowestCommonAncestor(root.left,p,q);
|
return root.left = lowestCommonAncestor(root.left,p,q);
|
||||||
return left !== null&&left;
|
|
||||||
}
|
}
|
||||||
if(root.val<p.val&&root.val<q.val) {
|
if(root.val<p.val&&root.val<q.val) {
|
||||||
// 向右子树查询
|
// 向右子树查询
|
||||||
let right = lowestCommonAncestor(root.right,p,q);
|
return root.right = lowestCommonAncestor(root.right,p,q);
|
||||||
return right !== null&&right;
|
|
||||||
}
|
}
|
||||||
return root;
|
return root;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue