递归转化为判断两个二叉树是否相同
class Solution {
public:
bool isSubtree(TreeNode* s, TreeNode* t) {
if(s==NULL) return false;
if(t==NULL) return true;
return isSubtree(s->left,t) || isSubtree(s->right,t) || isSameTree(s,t);
}
bool isSameTree(TreeNode* s, TreeNode* t){
if(s==NULL&&t==NULL) return true;
else if(s==NULL||t==NULL) return false;
else if(s->val==t->val) return isSameTree(s->left,t->left) && isSameTree(s->right,t->right);
else return false;
}
};