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);
}
设计算法查找二叉树的两个结点最近公共祖先(LCA)
猜你喜欢
转载自blog.csdn.net/lhf2112/article/details/70169896
今日推荐
周排行