# 1ms recursive Java Solution, easy to understand

• `````` public boolean isSymmetric(TreeNode root) {
if(root==null) return true;
return isMirror(root.left,root.right);
}
public boolean isMirror(TreeNode p, TreeNode q) {
if(p==null && q==null) return true;
if(p==null || q==null) return false;
return (p.val==q.val) && isMirror(p.left,q.right) && isMirror(p.right,q.left);
}``````

• very nice, elegant solution!! great understanding of recursion

• Thank you! :) I'm a green hand in programming actually.

• Thanks for your idea, this is really elegant!

• Gorgeous solution! The function isMirror is brilliant.

• wonderful solution! Really easy to understand, thank you

• good solution, easy to understand

• You solve my problem! Try to use a helper function when you can't solve it in the direct way.

• I found my solution very similar to yours, but with minor difference, which is more intuitive to myself.

``````public class Solution {
public boolean isSymmetric(TreeNode root) {
if(root==null)  return true;
return isSymmetric(root.left, root.right);
}

private boolean isSymmetric(TreeNode left, TreeNode right){
if(left==null && right==null)   return true;
if(left==null || right==null || left.val!=right.val)    return false;
return isSymmetric(left.left, right.right) && isSymmetric(right.left, left.right);
}
}
``````

• very easy to unstrand,thanks!

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.