题解 | #对称的二叉树#
对称的二叉树
https://www.nowcoder.com/practice/ff05d44dfdb04e1d83bdbdab320efbcb
/*
public class TreeNode {
int val = 0;
TreeNode left = null;
TreeNode right = null;
public TreeNode(int val) {
this.val = val;
}
}
*/
public class Solution {
boolean isSymmetrical(TreeNode pRoot) {
return judge(pRoot,pRoot);
}
boolean judge(TreeNode p, TreeNode q){
if(p==null&&q==null){
return true;
}else if(p==null || q==null){
return false;
}
return p.val==q.val && judge(p.left,q.right) && judge(q.left,p.right);
}
}
查看8道真题和解析
