/**
* 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) {
// write code here
if(root1 == NULL && root2 == NULL) return true;
if(root1 == NULL || root2 == NULL) return false;
return isEqual(root1, root2)
|| isContains(root1 -> left, root2)
|| isContains(root1 -> right, root2);
}
bool isEqual(TreeNode* root1, TreeNode* root2){
if(root1 == NULL && root2 == NULL) return true;
if(root1 == NULL || root2 == NULL) return false;
if(root1 -> val != root2 -> val) return false; //妈的智障题
return isEqual(root1 -> left, root2 -> left)
&& isEqual(root1 -> right, root2 -> right);
}
};
* 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) {
// write code here
if(root1 == NULL && root2 == NULL) return true;
if(root1 == NULL || root2 == NULL) return false;
return isEqual(root1, root2)
|| isContains(root1 -> left, root2)
|| isContains(root1 -> right, root2);
}
bool isEqual(TreeNode* root1, TreeNode* root2){
if(root1 == NULL && root2 == NULL) return true;
if(root1 == NULL || root2 == NULL) return false;
if(root1 -> val != root2 -> val) return false; //妈的智障题
return isEqual(root1 -> left, root2 -> left)
&& isEqual(root1 -> right, root2 -> right);
}
};