通过递归,判断左子树的左孩子跟右子树的右孩子,左子树的右孩子跟右子树的左孩子是否相等~
public class Solution { boolean isSymmetrical(TreeNode pRoot) { return pRoot == null || isCommon(pRoot.left,pRoot.right); } boolean isCommon(TreeNode leftNode, TreeNode rightNode){ if(leftNode == null && rightNode == null) return true; if(leftNode == null || rightNode == null) return false; return leftNode.val==rightNode.val && isCommon(leftNode.left,rightNode.right) && isCommon(leftNode.right,rightNode.left); } }