(Tree) 101. Symmetric Tree
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
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
public class Solution {
public boolean isSymmetric(TreeNode root) {
return isSymmetric(root,root);
}
public boolean isSymmetric(TreeNode t1,TreeNode t2) {
if(t1==null && t2==null) return true;
if(t1==null || t2==null) return false;
return(t1.val==t2.val && isSymmetric(t1.left,t2.right) && isSymmetric(t1.right,t2.left));
}
}
(Tree) 101. Symmetric Tree的更多相关文章
- [leetcode tree]101. Symmetric Tree
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For e ...
- [leetcode] 101. Symmetric Tree 对称树
题目大意 #!/usr/bin/env python # coding=utf-8 # Date: 2018-08-30 """ https://leetcode.com ...
- <LeetCode OJ> 101. Symmetric Tree
101. Symmetric Tree My Submissions Question Total Accepted: 90196 Total Submissions: 273390 Difficul ...
- Leetcode之101. Symmetric Tree Easy
Leetcode 101. Symmetric Tree Easy Given a binary tree, check whether it is a mirror of itself (ie, s ...
- leetcode 100. Same Tree、101. Symmetric Tree
100. Same Tree class Solution { public: bool isSameTree(TreeNode* p, TreeNode* q) { if(p == NULL &am ...
- Leetcode 笔记 101 - Symmetric Tree
题目链接:Symmetric Tree | LeetCode OJ Given a binary tree, check whether it is a mirror of itself (ie, s ...
- 101. Symmetric Tree
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For e ...
- 【LeetCode】101 - Symmetric Tree
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For e ...
- Java [Leetcode 101]Symmetric Tree
题目描述: Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). ...
随机推荐
- c51
ORG 0000HMOV R7,#08HMOV 83H,#01HMOV R4,#00HAA1:CLR P3.6 CLR P3.4 SETB P3.6 DJNZ R7,AA1AA2:JB P3.0,AA ...
- java连接sql server2005
转自:http://blog.sina.com.cn/s/blog_889b58310100zqyz.html 一:配置 第一步:在网上下载SQLServer2005的驱动包 http://www.m ...
- 吴奇隆刘诗诗婚礼场地:巴厘岛Ayana酒店,美到窒息!
导读:忍不住转载一下,原文地址:http://www.sjq315.com/news/270768.html 3月20日,吴奇隆和刘诗诗在巴厘岛五星级酒店Ayana Resort and Spa酒店举 ...
- C#使用quartz.net定时问题
因工作需要需要完成定时查询数据..因此在了解之后完成了一个demo 所需要的dll在该地址下载 http://pan.baidu.com/s/1sjNQLXV 首先引入quartz这个dll... 在 ...
- Angularjs directive
.directive('mydir',function(){ return{ multiElement: true/false, priority: number, //default: 0 term ...
- RestfulApi地址命名特点
get /orders 全部get /orders/{id} 根据id查找get /orders/{number} 根据编号查找get /orders/name/{name} 根据名称查找post / ...
- SQL增删改语句常用
创建table: create table tab_name( col1 type; 约束:主键-外键-非空-检查-唯一 col2 type; ); 删除表 : drop table tab_name ...
- ASP.NET Razor - C# 循环和数组
语句在循环中会被重复执行. For 循环 如果您需要重复执行相同的语句,您可以设定一个循环. 如果您知道要循环的次数,您可以使用 for 循环.这种类型的循环在向上计数或向下计数时特别有用: 实例 & ...
- Windows环境下npm install常见错误
Windows环境下npm install安装包依赖时,常出现一些错误,下面为个人解决办法: 错误一 缺少python环境: G:\nodejs\moviesite\node_modules\bcry ...
- Apache-Jemeter web性能测试工具使用
Jmeter是一款java开源的性能测试软件. 要使用该工具进行性能测试,首先需要下载该工具到你的电脑,接着配置java开发环境以及Jmeter环境.搭建完成之后,OK,我们就可以进行测试了. 测试第 ...