/**
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
/*
采用递归,如何是使用递归呢?
*/
class Solution {
public:
/**
*
* @param root1 TreeNode类
* @param root2 TreeNode类
* @return bool布尔型
*/
bool isContains(TreeNode* root1, TreeNode* root2) {
if (!root1) {
return false;
}
return isContains(root1->left, root2) || isContains(root1->right, root2) || isSubTree(root1, root2);
}
bool isSubTree(TreeNode* root1, TreeNode* root2) {
if (!root1 && !root2) {
return true;
}
if (!root1 || !root2 || root1->val != root2->val) {
return false;
}
return isSubTree(root1->left, root2->left) && isSubTree(root1->right, root2->right);
}
};