力扣101.对称二叉树
程序员文章站
2022-05-16 14:55:58
...
class Solution {
public boolean isSymmetric(TreeNode root) {
return check(root, root);
}
public boolean check(TreeNode p, TreeNode q){
if(p == null && q == null){
return true;
}
else if(p == null || q == null){
return false;
}
else{
return p.val == q.val && check(p.left, q.right) && check(p.right, q.left);
}
}
}