/**
* Created by lxw, liwei4939@126.com on 2017/10/30.
*/
public class T1ContainsT2 {
public static class Node{
public int value;
public Node left;
public Node right;
public Node(int data){
this.value = data;
}
}
public boolean contains(Node t1, Node t2){
return check(t1, t2) || contains(t1.left, t2) || contains(t1.right, t2);
}
public boolean check(Node t1, Node t2){
if(t2 == null){
return true;
}
if(t1 == null || t1.value != t2.value){
return false;
}
return check(t1.left,t2.left) && check(t1.right, t2.right);
}
}
判断t1树是否包含t2树全部相同的拓扑结构
最新推荐文章于 2022-06-23 13:46:30 发布