public boolean isSymmetric(TreeNode root) {
if (root == null) return true;
if (isEqual(root.left,root.right)) return true;
else return false;
}
public boolean isEqual(TreeNode root, TreeNode root1) {
if (root == null && root1 == null) return true;
if (root == null || root1 == null) return false;
if (root.val == root1.val) {
return isEqual(root.left, root1.right) && isEqual(root.right, root1.left);
}
else {
return false;
}
}
对称的二叉树
最新推荐文章于 2024-06-09 13:42:55 发布