Skip to content

Commit a83cebf

Browse files
add 951
1 parent 44e9b10 commit a83cebf

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
static int x = [](){std::ios::sync_with_stdio(false);cin.tie(0);return 0;}();
2+
class Solution
3+
{
4+
public:
5+
bool flipEquiv(TreeNode* root1, TreeNode* root2)
6+
{
7+
if (root1 == nullptr or root2 == nullptr) return root1 == root2;
8+
if (root1->val != root2->val) return false;
9+
return (flipEquiv(root1->left, root2->left) and flipEquiv(root1->right, root2->right)) or
10+
(flipEquiv(root1->left, root2->right) and flipEquiv(root1->right, root2->left));
11+
}
12+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution:
2+
def flipEquiv(self, root1, root2):
3+
"""
4+
:type root1: TreeNode
5+
:type root2: TreeNode
6+
:rtype: bool
7+
"""
8+
if root1 == None or root2 == None:
9+
return root1 == root2
10+
11+
if root1.val != root2.val:
12+
return False
13+
14+
return (self.flipEquiv(root1.left, root2.left) and self.flipEquiv(root1.right, root2.right)) or\
15+
(self.flipEquiv(root1.left, root2.right) and self.flipEquiv(root1.right, root2.left))

0 commit comments

Comments
 (0)