摘要: 这个树没有规定是二叉树。思路就是先求根到两个节点的路径,然后根据两条路径求的最低公共祖先。必须下面的图,I和G的最低祖先是A,I和J的最低公共祖先是D。完成的java代码如下:import java.util.*;public class NearistCommonFather { public TreeNode getNeariestCommonFather(TreeNode h,TreeNode n1,TreeNode n2){ if(h==null||n1==null||n2==null){ return null; } ... 阅读全文
posted @ 2013-10-07 17:59 orchid 阅读(451) 评论(0) 推荐(0) 编辑