package leetcode;
class demo11 {
public boolean isSymmetric(TreeNode root) {
return check(root,root);
}
public boolean check(TreeNode p,TreeNode q){
if (p==null&&q==null){
return true;
}
if (p==null||q==null){
return false;
}
return p.value==q.value&&check(p.left, q.right)&&check(p.right,q.left);
}
public static void main(String[] args) {
//树b
TreeNode b=new TreeNode(1);
b.left=new TreeNode(2);
b.left.left=new TreeNode(3);
b.left.right=new TreeNode(6);
b.right=new TreeNode(2);
b.right.left=new TreeNode(6);
b.right.right=new TreeNode(3);
demo11 ss=new demo11();
System.out.println(ss.isSymmetric(b));
}
}
leetcode#101对称二叉树
最新推荐文章于 2024-04-03 13:00:00 发布