(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). ...
随机推荐
- 关于MySQL5.6.25在Win7 64bit下重装后无法启动的解决方法
在重装MySQL5.6.25安装到进行配置的时候,一直在等待服务的启动.如果手动在系统服务启动会提示1067错误,这个错误在网上很常见,然而我试过了很多方法均无法解决. 于是看ProgramData\ ...
- Atom 安装 Packages 的笨办法
在终端里输入下面的命令打开 Atom 的 packages 的安装目录. open ~/.atom/packages 然后找到需要安装的 Atom packages ,比如我需要安装的这个 atom- ...
- 如何通过 js 修改微信浏览器的title?
document.setTitle = function(t) { document.title = t; var i = document.createElement('iframe'); i.sr ...
- 想一想social VR might just work
昨天玩了Oculus上的Casino VR(其实之前就知道这个瑞士公司,也下过standalone的PC client). 几把下来,居然觉得fun,总结起来: 1.是在一个immersive的环境中 ...
- sublime text 2 ubuntu安装及插件管理
参考 dudumao 1.下载Sublime Text2官网下载地址:http://www.sublimetext.com 2.安装Sublime Text2解压即可使用 $ sudo tar -jx ...
- 调用外部js文件测试
test <p><img id="img" onclick="javascript:var s=document.createElement('scri ...
- 记录自己对EventLoop和性能问题处理的一点心得
1.EventLoop 这里说的EventLoop不是指某一个具体的库或是框架,而是指一种程序实现结构.这种结构多是基于IO多路转接的API(select.poll.epoll之类)以reactor模 ...
- jQuery获取字符串中两个字符之间的字符
//获取@和.之间的字符 var str1 = "laxe@ll.com"; var str2 = str1.substring(str1.indexOf('@')+1,str1. ...
- Flask-SQLAlchemy 的操作
from flask_sqlalchemy import SQLAlchemy app = Flask(__name__) db = SQLAlchemy(app) ================= ...
- eclipse安装ADT后在windows菜单下找不到android SDK and AVD Manager
eclipse安装ADT后在windows菜单下找不到android SDK and AVD Manager选项的解决办法 - zhjr1220的专栏 - 博客频道 - CSDN.NET http: ...