题目链接
思路
DFS 递归解决
代码
class Solution {
public boolean isSymmetric(TreeNode root) {
if(root == null){
return true;
}
return dfs(root.left, root.right);
}
boolean dfs(TreeNode left, TreeNode right){
if(left == null && right == null){
return true;
}else if((left == null && right != null) || (left != null && right == null)){
return false;
}else if(left.val == right.val){
return dfs(left.left, right.right) && dfs(left.right, right.left);
}
return false;
}
}
标签:101,return,dfs,right,二叉树,&&,null,LeetCode,left
From: https://www.cnblogs.com/shixuanliu/p/17062520.html