题解 | #对称的二叉树#
对称的二叉树
https://www.nowcoder.com/practice/ff05d44dfdb04e1d83bdbdab320efbcb
/* 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 isSame(pRoot.left,pRoot.right); } public static boolean isSame(TreeNode t1, TreeNode t2){ if(t1 == null ^ t2 == null){ return false; } if(t1==null && t2 == null){ return true; } boolean b1 = t1.val == t2.val; boolean b2 = isSame(t1.left,t2.right); boolean b3 = isSame(t1.right,t2.left); return b1 && b2 && b3; } }