【剑指offer-解题系列(59)】对称的二叉树
来源:互联网 发布:网络运维 英文缩写 编辑:程序博客网 时间:2024/05/19 17:22
题目描述
请实现一个函数,用来判断一颗二叉树是不是对称的。注意,如果一个二叉树同此二叉树的镜像是同样的,定义其为对称的。
分析
递归实现
代码实现
bool isSymmetrical(TreeNode* root)
{if(!root)
return true;
return isSymmetrical( root->right, root->left);
}
bool isSymmetrical(TreeNode* root1,TreeNode* root2)
{
if(!root1&&!root2)
return true;
if(!root1&&root2)
return false;
if(root1&&!root2)
return false;
return isSymmetrical( root1->left, root2->right)&&
isSymmetrical( root1->right, root2->left)&&
root2->val == root1->val;
}
阅读全文
0 0
- 【剑指offer-解题系列(59)】对称的二叉树
- 【剑指offer-解题系列(39)】二叉树的深度
- 剑指offer 59 - 对称的二叉树
- 《剑指offer》:[59]对称的二叉树
- 剑指offer系列之五十六:对称二叉树的判断
- 剑指offer系列之57:对称二叉树的判断
- (剑指Offer)面试题59:对称的二叉树
- (剑指Offer)面试题59:对称的二叉树
- 【剑指offer-解题系列(4)】重建二叉树
- 【剑指offer-解题系列(22)】从上到下打印二叉树
- 【剑指offer-解题系列(62)】序列化二叉树
- 剑指offer--对称的二叉树
- 《剑指offer》对称的二叉树
- 剑指offer-对称的二叉树
- 剑指offer—对称的二叉树
- 剑指offer:对称的二叉树
- 剑指offer:对称的二叉树
- [剑指offer]对称的二叉树
- 内部类
- 李开复 反思前半生 感悟
- unit10-Bash scripts 1
- (6/13)JSTL标签库
- 【MFC】多线程计算圆周率π的值
- 【剑指offer-解题系列(59)】对称的二叉树
- 流程控制语句—顺序结构语句及键盘录入
- Linux日常——信号(3)之线程安全和可重入函数
- Remove Duplicates from Sorted List
- thinkphp循环数据到页面时,jquery$(this)动态获取指定元素的数据
- Spring Boot (教程四:配置文件)
- c语言hello world开始
- Spring Security-/logout 退出404
- 【POJ 1001】Exponentiation 题解&代码(c++)