-
Notifications
You must be signed in to change notification settings - Fork 77
/
solution.cpp
34 lines (33 loc) · 911 Bytes
/
solution.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
bool eq(TreeNode* n1, TreeNode* n2){
if(n1 == NULL && n2 == NULL)
return true;
else if(n1 == NULL || n2 == NULL)
return false;
else{
if(n1->val == n2->val)
return true;
}
return false;
}
bool flipEquiv(TreeNode* root1, TreeNode* root2) {
if(eq(root1,root2)){
if(root1 != NULL){
return flipEquiv(root1->left, root2->left) && flipEquiv(root1->right, root2->right)
|| flipEquiv(root1->left, root2->right) && flipEquiv(root1->right, root2->left);;
}
return true;
}
return false;
}
};