题目
C#代码
public class Solution
{
public TreeNode
LowestCommonAncestor(TreeNode root
, TreeNode p
, TreeNode q
) {
if(root
== null
) return null
;
if(root
.val
== p
.val
|| root
.val
== q
.val
)
{
return root
;
}
var left
= LowestCommonAncestor(root
.left
,p
,q
);
var right
= LowestCommonAncestor(root
.right
,p
,q
);
if(left
==null
) return right
;
if(right
== null
) return left
;
return root
;
}
}
转载请注明原文地址:https://ipadbbs.8miu.com/read-7958.html