bool isSubtree(TreeNode *T1, TreeNode *T2)
{
// write your code here
if(T2 == NULL)//空树是任何非空树子集
return true;
if(T1 == NULL)//直接返回false
return false;
else
return isEqualTree(T1,T2)||isSubtree(T1->right,T2)||isSubtree(T1->left,T2);//逐个节点判断
}
bool isEqualTree(TreeNode *a, TreeNode *b)//判断是否为等价二叉树
{
if(a==NULL && b==NULL)
return true;
if((a==NULL && b!=NULL)||(a!=NULL && b==NULL))
return false;
if(a->val==b->val)
{
return isEqualTree(a->left,b->left) && isEqualTree(a->right,b->right);
}
return false;
}