public static BinaryTreeNode<Integer> LCA(BinaryTreeNode<Integer> root,BinaryTreeNode<Integer> a, BinaryTreeNode<Integer> b){
BinaryTreeNode<Integer> left,right;
if(root==null)
return root;
if(root==a|| root==b)
return root;
left = LCA(root.getleft(),a,b);
right = LCA(root.getright(),a,b);
if(left!=null && right!=null)
return root;
else
return(left!=null?left:right);
}
转载请注明原文地址: https://ju.6miu.com/read-672963.html