Java solution
\npublic boolean flipEquiv(TreeNode root1, TreeNode root2) {\n        LinkedList<TreeNode> bfs = new LinkedList<>();\n        bfs.add(root1);\n        bfs.add(r
```\npublic boolean flipEquiv(TreeNode root1, TreeNode root2) {\n        LinkedList<TreeNode> bfs = new LinkedList<>();\n        bfs.add(root1);\n        bfs.add(root2);\n        while(!bfs.isEmpty()) {\n            TreeNode node1 = bfs.remove();\n            TreeNode node2 = bfs.remove();\n            if (!equal(node1, node2)) {\n                return false;\n            }\n            if (node1 == null && node2 == null) {\n                continue;\n            }            \n            if (equal(node1.left, node2.left) && equal(node1.right, node2.right)) {\n                bfs.add(node1.left);\n                bfs.add(node2.left);\n                bfs.add(node1.right);\n                bfs.add(node2.right);\n                continue;\n            }\n            if (equal(node1.left, node2.right) && equal(node1.right, node2.left)) {\n                bfs.add(node1.left);\n                bfs.add(node2.right);\n                bfs.add(node1.right);\n                bfs.add(node2.left);\n                continue;\n            }\n            return false;\n        }\n        return true;\n    }\n\n    private boolean equal(TreeNode root1, TreeNode root2) {\n        return root1 == null && root2 == null || (root1 != null && root2 != null && root1.val == root2.val);\n    }\n```
[]