(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). ...
随机推荐
- Nginx转发地址解决跨域问题
什么是跨域问题 在一个服务器A里放置了json文件,另一个服务器B想向A发送ajax请求,获取此文件,会发生错误. Chrome提示: XMLHttpRequest cannot load ***** ...
- html+css基础知识总结
1.HTML书写的基本规范 img标签必须得写alt="" 标签名和属性名字必须小写 引号必须用双引号 双标签必须有闭合标签 单标 ...
- 【Cocos2d-x 3.x】 事件处理机制源码分析
在游戏中,触摸是最基本的,必不可少的.Cocos2d-x 3.x中定义了一系列事件,同时也定义了负责监听这些事件的监听器,另外,cocos定义了事件分发类,用来将事件派发出去以便可以实现相应的事件. ...
- IDEA IntelliJ常用设置以及快捷键(转)
转载自:http://macrochen.iteye.com/blog/1035680 关于字体的设置 IDEA下使用雅黑Consolas混合字体 快捷贱, 快捷贱 , 快捷键贱 In ...
- 【jQuery plug-in】DataTables
1. DOM Position dataTableOption.dom = '<"top"<"pull-left"l><"pu ...
- LeetCode 【318. Maximum Product of Word Lengths】
Given a string array words, find the maximum value of length(word[i]) * length(word[j]) where the tw ...
- 2016HUAS_ACM暑假集训4M - 基础DP
简单的0-1背包问题,大家都会做的.题意不想解释太多. 简述题目的案例及以几个关键 Sample Input 1 //测试组数T 5 10 ...
- 【OpenGL】VAO与VBO
1.我们先了解什么是OpenGL对象(OpenGL Object) 根据OpenGL Wiki的定义: An OpenGL Object is an OpenGL construct that con ...
- SDK Manager 中 没有 Support Library怎么弄?
SDK Manager 中 没有 Support Library怎么弄?求大神帮忙 百度上面说的基本都试了,依旧没有弄出来 点击"Packages" > "Show ...
- InfoPi运行机制介绍
整体工作框架 文件目录结构 数据库设计 程序开发框架 注:图片可能被自动缩小,可以另存看大图 1.整体工作框架. 通用户关注绿色竖线左侧的内容即可 2.InfoPi的文件目录结构. 请留意一下cfg目 ...