二叉树的题向来都是一看就会,一写就废
public class Solution { /** * * @param root TreeNode类 * @return bool布尔型 */ public boolean isSymmetric (TreeNode root) { // write code here return root == null || isSymmetric(root.left,root.right); } public 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(left.right,right.left); } }