---
# System prepended metadata

title: 0951. Flip Equivalent Binary Trees
tags: [Leetcode, Tree, Medium]

---

# 0951. Flip Equivalent Binary Trees
###### tags: `Leetcode` `Medium` `Tree`
Link: https://leetcode.com/problems/flip-equivalent-binary-trees/description/
## Code
```java=
class Solution {
    public boolean flipEquiv(TreeNode root1, TreeNode root2) {
        if(root1==null && root2==null) return true;
        if(root1==null || root2==null || root1.val!=root2.val) return false;
        if(root1.val==root2.val && flipEquiv(root1.left, root2.left) && flipEquiv(root1.right, root2.right)) return true;
        if(root1.val==root2.val && flipEquiv(root1.left, root2.right) && flipEquiv(root1.right, root2.left)) return true;
        return false;
    }
}
```