题目描述:
解析:递归,看根节点左右孩子是否是镜像树
class Solution {
public boolean isSymmetric(TreeNode root) {
if (root == null) return false;
return isMirror(root.left, root.right);
}
private boolean isMirror(TreeNode root1, TreeNode root2) {
if (root1 == null && root2 == null) return true; //说明都已经匹配完成
if (root1 == null || root2 == null) return false; //说明还没有匹配完
if (root1.val != root2.val) return false; //表明匹配错误
return isMirror(root1.left, root2.right) && isMirror(root1.right, root2.left);
}
}