Skip to content

Commit 2c1a05e

Browse files
committed
Time: 0 ms (100%), Space: 14.5 MB (84.24%) - LeetHub
1 parent e3f65cd commit 2c1a05e

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Definition for a binary tree node.
3+
* struct TreeNode {
4+
* int val;
5+
* TreeNode *left;
6+
* TreeNode *right;
7+
* TreeNode() : val(0), left(nullptr), right(nullptr) {}
8+
* TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
9+
* TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
10+
* };
11+
*/
12+
class Solution {
13+
public:
14+
bool flipEquiv(TreeNode* root1, TreeNode* root2) {
15+
if (!root1 && !root2) return true;
16+
if (!root1 || !root2) return false;
17+
if (root1->val != root2->val) return false;
18+
bool ok = flipEquiv(root1->left, root2->left) && flipEquiv(root1->right, root2->right);
19+
if (ok) return true;
20+
return flipEquiv(root1->left, root2->right) && flipEquiv(root1->right, root2->left);
21+
}
22+
};

0 commit comments

Comments
 (0)