Java recursion
\nclass Solution {\n    public boolean flipEquiv(TreeNode root1, TreeNode root2) {\n        if (root1 == null && root2 == null) {\n            return true;\n   
```\nclass Solution {\n    public boolean flipEquiv(TreeNode root1, TreeNode root2) {\n        if (root1 == null && root2 == null) {\n            return true;\n        }\n        if (root1 == null || root2 == null) {\n            return false;\n        }\n        if (root1.val != root2.val) {\n            return false;\n        }\n        if (flipEquiv(root1.left, root2.left) && flipEquiv(root1.right, root2.right) ||\n           flipEquiv(root1.left, root2.right) && flipEquiv(root1.right, root2.left)) {\n            return true;\n        }\n        return false;\n    }\n}\n```
[]