标签:
public class Solution { public boolean HasSubtree(TreeNode T1, TreeNode T2) { if (T2 == null || T1==null) { return false; } if (isEqual(T1, T2)) { return true; } if (HasSubtree(T1.left, T2) || HasSubtree(T1.right, T2)) { return true; } return false; } private boolean isEqual(TreeNode T1, TreeNode T2) { if (T2 == null) { return true; } if(T1 == null){ return false; } if (T1.val != T2.val) { return false; } return isEqual(T1.left, T2.left) && isEqual(T1.right, T2.right); } }
标签:
原文地址:http://www.cnblogs.com/hesier/p/5585147.html