class Solution {
public boolean isSymmetric(TreeNode root) {
return check(root,root);
}
boolean check(TreeNode p,TreeNode q){
if(p==null&&q==null) return true;
if(p==null||q==null) return false;
return (p.val==q.val)&&(check(p.left,q.right))&&(check(p.right,q.left));
}
}
leetcode101. 对称二叉树
最新推荐文章于 2025-04-03 15:29:45 发布