C++ solution, Recursive, with illustrated explanation and example
We can recursively check the following conditions:\n1. If one of trees is NULL while the other one is not return false\n2. Otherwise, we know that both trees ar
We can recursively check the following conditions:\n1. If one of trees is NULL while the other one is not return false\n2. Otherwise, we know that both trees are NULL or not NULL. \n\t* If both of them are NULL we are fine. \n\t* If none of them are NULL, then we need to make sure\n\t\t* They have same value\n\t\t* Recursively calls this function for both of their children. \n\t\t* We need to make sure whether they have exactly same children (fig1) or they will be same if we flip their children (fig2).\n\n![image](https://assets.leetcode.com/users/ashkanxy/image_1543725130.png)\n\n![image](https://assets.leetcode.com/users/ashkanxy/image_1543725142.png)\n\n\n```\n    bool flipEquiv(TreeNode* root1, TreeNode* root2) {\n        if ((root1==NULL && root2!=NULL) || (root1!=NULL && root2==NULL)){            \n            return false;            \n        } else if (root1!= NULL) {  \n/*which means none of them is NULL, since with previous if condition we made sure both of them are NULL or none of them is NULL*/\n            return ( (root1->val ==root2->val) && (\n                         (flipEquiv (root1->right, root2->left) && flipEquiv (root1->left, root2->right) )  ||\n                         (flipEquiv (root1->left, root2->left) && flipEquiv (root1->right, root2->right) )  )  );                              \n        } else \n            return true;        \n    }\n```
[]