0ms | JAVA | 10 Lines | Recursive | EXPLAINING FULL | FEW LINES | EASY TO UNDERSTAND
So the solution is a little simple, \nthe first step is  how to build the algorithm if two tree is the same (The link about that excercise https://leetcode.com/
So the solution is a little simple, \nthe first step is  how to build the algorithm if two tree is the same (The link about that excercise https://leetcode.com/problems/same-tree/)  \n\nThis is the code to compare if two **tree is the same** (https://leetcode.com/problems/same-tree/discuss/32687/Five-line-Java-solution-with-recursion)\n\n```\npublic boolean isSameTree(TreeNode p, TreeNode q) {\n    if(p == null && q == null) return true;\n    if(p == null || q == null) return false;\n    if(p.val == q.val)\n        return isSameTree(p.left, q.left) && isSameTree(p.right, q.right);\n    return false;\n}\n```\n\nSo, When we developed the excersice before so we only have a little change for do this excercise. The change is the method isSameTree, how the root in the middle have a mirror so in the part of isSameTree we only do a reverse so we compare left with right and right with left. \n\nAnd the call with the root \n\n```\nclass Solution {\n    public boolean isSymmetric(TreeNode root) {        \n        return isSameTree(root.right, root.left);\n    }\n    \n   public boolean isSameTree(TreeNode p, TreeNode q) {\n        if(p == null && q == null) return true;\n        if(p == null || q == null) return false;\n        if(p.val == q.val)\n            return isSameTree(p.left, q.right) && isSameTree(p.right, q.left);\n        return false;\n    }\n}\n```
['Recursion', 'Java']