题解 | #拼凑面额#
树的子结构
http://www.nowcoder.com/practice/6e196c44c7004d15b1610b9afca8bd88
public class Solution { public boolean HasSubtree(TreeNode root1,TreeNode root2) { if(root2==null||root1==null)return false; if(root1.val==root2.val){ if(isSubTree(root1,root2))return true; } return HasSubtree(root1.left,root2)||HasSubtree(root1.right,root2); } public boolean isSubTree(TreeNode root1,TreeNode root2){ if(root2==null)return true; if(root1==null)return false; if(root1.val!=root2.val)return false; return isSubTree(root1.left,root2.left)&&isSubTree(root1.right,root2.right); }