树的子结构
作者:互联网
public boolean isSubStructure(TreeNode A, TreeNode B) {
if (A == null || B == null) return false;
if (isEqual(A, B)) {
return true;
}
else {
return isSubStructure(A.left, B) || isSubStructure(A.right, B);
}
}
public boolean isEqual(TreeNode a, TreeNode b) {
if (b == null) return true;
if (a == null || a.val != b.val) {
return false;
}
else {
return isEqual(a.left, b.left) && isEqual(a.right, b.right);
}
}
标签:right,TreeNode,子结构,isEqual,return,null,left 来源: https://blog.csdn.net/Lily8888888/article/details/113077769