✅BEATS 100% | DFS | JAVA | EXPLAINED🔥🔥🔥
Approach:\n\nEmploys a recursive approach to compare the left and right subtrees of the root node.\nThe isSameTree function compares two nodes for equality and 
**Approach:**\n\nEmploys a recursive approach to compare the left and right subtrees of the root node.\nThe isSameTree function compares two nodes for equality and recursively compares their corresponding subtrees.\nThe isSymmetric function calls isSameTree with the root node as both arguments, effectively comparing the left and right subtrees of the entire tree.\n\n**Time Complexity: O(n)**\n\nThe code visits each node of the tree once, resulting in linear time complexity with respect to the number of nodes (n).\n\n**Space Complexity: O(h)**\n\nThe space complexity is determined by the maximum depth of the tree (h). In the worst case (a skewed tree), the recursion stack can reach a depth of h, leading to O(h) space usage.\n\n# Code\n```java []\n/**\n * Definition for a binary tree node.\n * public class TreeNode {\n *     int val;\n *     TreeNode left;\n *     TreeNode right;\n *     TreeNode() {}\n *     TreeNode(int val) { this.val = val; }\n *     TreeNode(int val, TreeNode left, TreeNode right) {\n *         this.val = val;\n *         this.left = left;\n *         this.right = right;\n *     }\n * }\n */\nclass Solution {\n    public boolean isSymmetric(TreeNode root) {\n        boolean ans= isSameTree(root.left, root.right);\n        return ans;\n    }\n//(Imp)  here we want a mirror so for that , Ro Ro will be same and for Tree 1 when we are moving left at the same time for tree2 we will moce right\n       //when for tree1 moving right at same time mmove tree2 to right which will give you a mirror \n    public boolean isSameTree(TreeNode p, TreeNode q) {\n        if(p == null || q == null){\n            return p == q;\n        }\n\n        return (p.val == q.val) && isSameTree(p.left , q.right) && isSameTree(p.right, q.left); \n         // it means the curr vals , the ones coming from left and coming from right all 3 should be true then return true , if either on is false it will reuturn false\n    }\n    \n}\n```
['Java']