File tree 2 files changed +27
-0
lines changed
src/0951-Flip-Equivalent-Binary-Trees
2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change
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 number Diff line number Diff line change
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 ))
You can’t perform that action at this time.
0 commit comments