Dart || DFS (Recursion) || 2 line logic
Intuition\n Describe your first thoughts on how to solve this problem. \nThe problem involves checking whether two binary trees can be made identical by perform
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem involves checking whether two binary trees can be made identical by performing flip operations, where you can swap any node\'s left and right subtrees. The approach revolves around recursive comparisons of nodes and their subtrees in both their original order and in a flipped order.\n\n\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n- Base Case:\n\n    If both root1 and root2 are null, they are flip equivalent (true).\n\n    If only one of them is null or their values differ, they are not flip equivalent (false).\n\n-   Recursive Checks:\n\n    Without Flipping: Recursively check if root1.left matches root2.left and root1.right matches root2.right.\n\n    With Flipping: Recursively check if root1.left matches root2.right and root1.right matches root2.left.\n\n- Return Condition:\n\n    Return true if either recursive check (with or without flipping) returns true.\n    Return false if none of the checks satisfy the conditions.\n\n# Complexity\n- Time complexity: \uD835\uDC42(\uD835\uDC5B), where \uD835\uDC5B is the number of nodes in the smaller tree. Each node is visited exactly once.\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(h), where \u210E is the height of the tree due to the recursive calls on the call stack.\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n/**\n * Definition for a binary tree node.\n * class TreeNode {\n *   int val;\n *   TreeNode? left;\n *   TreeNode? right;\n *   TreeNode([this.val = 0, this.left, this.right]);\n * }\n */\nclass Solution {\n  bool flipEquiv(TreeNode? root1, TreeNode? root2) {\n    if (root1 == null && root2 == null) {\n      return true;\n    }\n\n    if (root1 == null || root2 == null || root1.val != root2.val) {\n      return false;\n    }\n\n    // check without flipping\n    bool withoutFlip = flipEquiv(root1.left, root2.left) && flipEquiv(root1.right, root2.right);\n\n    // check with flipping\n    bool withFlip = flipEquiv(root1.left, root2.right) && flipEquiv(root1.right, root2.left);\n\n    return withFlip || withoutFlip;\n  }\n}\n```
['Tree', 'Depth-First Search', 'Recursion', 'Binary Tree', 'Dart']