LeetCode 101. Symmetric Tree
2016-04-17 22:25
330 查看
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).
For example, this binary tree is symmetric:
But the following is not:
For example, this binary tree is symmetric:
1 / \ 2 2 / \ / \ 3 4 4 3
But the following is not:
1 / \ 2 2 \ \ 3 3
static bool isSymmetric(TreeNode* left, TreeNode* right) { if(!left && !right) return true; if(!left && right) return false; if(!right && left) return false; return left->val == right->val && isSymmetric(left->left, right->right) && isSymmetric(left->right, right->left); } bool isSymmetric(TreeNode* root) { if(!root) return true; return isSymmetric(root->left, root->right); }
相关文章推荐
- java学习笔记(2)基本数据类型对象包装类
- CSS相关知识二
- 周结
- json中date类型数据为空造成转JAVA对象失败
- 开源ckplayer 网页播放器, 跨平台(html5, mobile),flv, f4v, mp4, rtmp协议. webm, ogg, m3u8 !
- iOS 通知传值(逆传)
- 蛇形矩阵 (长沙理工大学第十一届程序设计竞赛)
- 开源项目托管GitHub
- asp.net发送短信
- 20145127《java程序设计》第七周学习总结
- JavaScript对象
- JAVA Apache-CommonsCollections 序列化RCE漏洞分析
- kettle中的分组的作用
- RESTFul API 个人理解
- 中国两弹一星元勋——郭永怀
- 笔记本装 Win10 后的亮度调节和 WiFi 问题
- 第七届科技节数学建模比赛附录
- NYOJ-小猴子下落
- linux之DNS部署
- bool数组初始化