递归,判断左子树的左子树与右子树的右子树是否相同,左子树的右子树与右子树的左子树是否相同
class Solution {
public boolean isSymmetric(TreeNode root) {
if(root == null) return true;
return dfs(root.left, root.right);
}
private boolean dfs(TreeNode root_left, TreeNode root_right){
if(root_left == null && root_right == null) return true;
if(root_left == null || root_right == null) return false;
if(root_left.val != root_right.val) return false;
return dfs(root_left.left, root_right.right) && dfs(root_left.right, root_right.left);
}
}