Skip to content

Commit abff2d1

Browse files
authored
Merge pull request neetcode-gh#2533 from Anukriti167/patch-10
Create 0951-flip-equivalent-binary-trees.java
2 parents cdfcdd9 + 6df3c37 commit abff2d1

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
public boolean flipEquiv(TreeNode root1, TreeNode root2) {
3+
if(root1 == null && root2 == null) return true;
4+
if(root1 == null || root2 == null) return false;
5+
if(root1.val != root2.val) return false;
6+
7+
if(flipEquiv(root1.left, root2.left) && flipEquiv(root1.right, root2.right)){ //if they are euqal
8+
return true;
9+
}
10+
if(flipEquiv(root1.right, root2.left) && flipEquiv(root1.left, root2.right)){ // if flipped once
11+
return true;
12+
}else{
13+
return false;
14+
}
15+
}
16+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy