LeetCode_101 Symmetric Tree
2015-07-15 14:43
477 查看
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).
For example, this binary tree is symmetric:
1
/ \
2 2
/ \ / \
3 4 4 3
But the following is not:
1
/ \
2 2
\ \
3 3
For example, this binary tree is symmetric:
1
/ \
2 2
/ \ / \
3 4 4 3
But the following is not:
1
/ \
2 2
\ \
3 3
public boolean isSymmetric(TreeNode root) { if (root ==null) return true; return symmetric(root.left, root.right); } private boolean symmetric(TreeNode left, TreeNode right){ if (left == null && right ==null) return true; if (left !=null && right !=null &&right.val == left.val) { return symmetric(left.right, right.left)&&symmetric(left.left, right.right); }else { return false; } }
相关文章推荐
- JAVA下AES256加密
- UVA10020 Minimal coverage 贪心
- 数据加密
- mysql中二进制形式保存文件数据
- 大数类简单模板
- 扩展方法(Extension Method)
- 不定高宽的元素居中的方法
- CentOS服务器Http压力测试之ab
- virtualenv 环境下 Flask + Nginx + Gunicorn+ Supervisor 搭建 Python Web
- Java创建多线程的两种方式对比
- Swift 集合类型(Collection Type) 之 set(官方文档翻译及总结)
- [Win32SDK基本]ListView Controls(2)Report (details) View 详解(续)
- poj1144
- Connect模块解析
- sourceinsight 添加quicker.em生效
- iOS - 正则表达式判断邮箱、身份证..是否正确
- java多线程编程之捕获子线程异常示例
- java 抓取网页内容小工具
- VC中CString和WPARAM之间的相互转换
- 定义结构体时变量名后的冒号和数字