判断是不是二叉树的子树
public class Solution {
public boolean isSubStructure(TreeNode A, TreeNode B){
if (A==null||B==null) return false;
return dfs(A,B)||isSubStructure(A.left,B)||isSubStructure(A.right,B);
}
public boolean dfs(TreeNode A, TreeNode B){
if (B==null) return true;
if (A==null) return false;
return A.val==B.val && dfs(A.left, B.left) && dfs(A.right, B.right);
}
}