/*
struct TreeNode {
int val;
struct TreeNode *left;
struct TreeNode *right;
TreeNode(int x) :
val(x), left(NULL), right(NULL) {
}
};*/
class Solution {
public:
bool HasSubtree(TreeNode* pRoot1, TreeNode* pRoot2)
{
bool res=false;
if(pRoot1 == NULL || pRoot2==NULL)
return false;
if(pRoot1->val==pRoot2->val){
res=Tree1hasTree2(pRoot1,pRoot2);
}
if(!res){
res=HasSubtree(pRoot1->left,pRoot2);
}
if(!res){
res=HasSubtree(pRoot1->right,pRoot2);
}
return res;
}
public:
bool Tree1hasTree2(TreeNode* Node1, TreeNode* Node2){
if(Node2==NULL)
return true;
if(Node1==NULL)
return false;
if(Node1->val!=Node2->val)
return false;
return Tree1hasTree2(Node1->left,Node2->left) && Tree1hasTree2(Node1->right,Node2->right);
}
};