@@ -25,14 +25,14 @@ impl TreeNode {
25
25
26
26
#[ allow( unused) ]
27
27
impl Solution {
28
- pub fn lowest_common_ancestor ( root : Option < Rc < RefCell < TreeNode > > > , p : Option < Rc < RefCell < TreeNode > > > , q : Option < Rc < RefCell < TreeNode > > > ) -> Option < Rc < RefCell < TreeNode > > > {
28
+ pub fn lowest_common_ancestor_2 ( root : Option < Rc < RefCell < TreeNode > > > , p : Option < Rc < RefCell < TreeNode > > > , q : Option < Rc < RefCell < TreeNode > > > ) -> Option < Rc < RefCell < TreeNode > > > {
29
29
// 方法1
30
30
if root. is_none ( ) { return None ; }
31
31
if root == p || root == q { return root; }
32
32
let left = root. as_ref ( ) . unwrap ( ) . borrow ( ) . left . clone ( ) ;
33
33
let right = root. as_ref ( ) . unwrap ( ) . borrow ( ) . right . clone ( ) ;
34
- let left_parent = Self :: lowest_common_ancestor ( left, p. clone ( ) , q. clone ( ) ) ;
35
- let right_parent = Self :: lowest_common_ancestor ( right, p. clone ( ) , q. clone ( ) ) ;
34
+ let left_parent = Self :: lowest_common_ancestor_2 ( left, p. clone ( ) , q. clone ( ) ) ;
35
+ let right_parent = Self :: lowest_common_ancestor_2 ( right, p. clone ( ) , q. clone ( ) ) ;
36
36
if left_parent. is_none ( ) { return right_parent; }
37
37
if right_parent. is_none ( ) { return left_parent; }
38
38
root
0 commit comments