Given a binary tree, check whether it is mirror – symmetric. For example, binary trees [1,2,2,3,4,4,3] are symmetric.

 public boolean isSymmetric(TreeNode root) {
       return  isMirror(root,root);
    }
     private boolean isMirror(TreeNode t1, TreeNode t2){
        if (t1 == null && t2 == null){
            return true;
        }
        if (t1 == null || t2 == null){
            return false; } // The left subtree of P1 is recursively equal to the pomelo tree of P2return (t1.val == t2.val)&&isMirror(t1.left,t2.right)&&isMirror(t1.right,t2.left);
    }

Copy the code