public boolean isSymmetric(TreeNode root) {
if(root == null) return true;
TreeNode tmp = reverse(root);
if(tmp == root){
return true;
}
return false;
}
private TreeNode reverse(TreeNode root){
if(root == null) return root;
TreeNode tmp = root.left;
root.left = root.right;
root.right = tmp;
reverse(root.left);
reverse(root.right);
return root;
}
Is there any error in it,please tell me


You code seems reverse any nodes in the tree, when it is a leaf node the reverse will return null.
How could you use this to tell if a tree is a symmetric tree?Here is my solution, if a tree is a symmetric tree, its left subtree and its right subtree shoudl be symmetric to each other
public class Solution { public boolean isSymmetricSubTree(TreeNode left, TreeNode right){ if(left==null&&right==null) return true; if(left==null&&right!=nullright==null&&left!=null) return false; if(left.val!=right.val) return false; return isSymmetricSubTree(left.left, right.right)&&isSymmetricSubTree(left.right,right.left); } public boolean isSymmetric(TreeNode root) { if(root==null) return true; return isSymmetricSubTree(root.left,root.right); } }