C++ Recursive Solution with Explanation
\nclass Solution {\npublic:\n    bool flipEquiv(TreeNode* root1, TreeNode* root2) {\n        // Two null trees are flip equivalent\n        // A non-null and nu
```\nclass Solution {\npublic:\n    bool flipEquiv(TreeNode* root1, TreeNode* root2) {\n        // Two null trees are flip equivalent\n        // A non-null and null tree are NOT flip equivalent\n        // Two non-null trees with different root values are NOT flip equivalent\n        // Two non-null trees are flip equivalent if\n        //      The left subtree of tree1 is flip equivalent with the left subtree of tree2 and the right subtree of tree1 is   \n        //      flipequivalent with the right subtree of tree2 (no flip case)\n        //      OR\n        //      The right subtree of tree1 is flip equivalent with the left subtree of tree2 and the left subtree of tree1 is\n        //      flipequivalent with the right subtree of tree2 (flip case)\n        if ( !root1 && !root2 ) return true;\n        if ( !root1 && root2 || root1 &&!root2 || root1->val != root2->val ) return false;\n        return flipEquiv( root1->left, root2->left ) && flipEquiv( root1->right, root2->right )\n            || flipEquiv( root1->right, root2->left ) && flipEquiv( root1->left, root2->right );\n    }\n};\n```
[]