/* public class TreeNode { int val = 0; TreeNode left = null; TreeNode right = null; public TreeNode(int val) { this.val = val; } } */ public class Solution { //一棵树对称,那么其左子树和右子树也应对称 boolean isSymmetrical(TreeNode pRoot) { if(pRoot == null) { return true ; } return isMirror(pRoot.left , pRoot.right) ; } //判断两棵树是否对称 boolean isMirror(TreeNode r1 , TreeNode r2) { if(r1 == null && r2 == null) { return true ; } if(r1 == null || r2 == null) { return false ; } if(r1.val != r2.val) { return false ; } return isMirror(r1.left , r2.right) && isMirror(r1.right,r2.left); } }