LeetCode——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
中文:给定一二叉树,检查它是否是它自己的镜像(比如,以中心对称)。
递归:
public boolean isSymmetric(TreeNode root) {
if(root == null)
return true;
return isSymmetric(root,root);
}
public boolean isSymmetric(TreeNode left,TreeNode right) {
if(left == null && right == null)
return true;
else if(left == null || right == null)
return false;
return left.val == right.val && isSymmetric(left.left,right.right) && isSymmetric(left.right,right.left);
}
LeetCode——Symmetric Tree的更多相关文章
- LeetCode: Symmetric Tree 解题报告
Symmetric Tree Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its ...
- [LeetCode] Symmetric Tree 判断对称树
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For e ...
- [leetcode]Symmetric Tree @ Python
原题地址:https://oj.leetcode.com/problems/symmetric-tree/ 题意:判断二叉树是否为对称的. Given a binary tree, check whe ...
- 二叉树系列 - [LeetCode] Symmetric Tree 判断二叉树是否对称,递归和非递归实现
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For e ...
- [Leetcode] Symmetric tree 对称二叉树
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For e ...
- Python3解leetcode Symmetric Tree
问题描述: Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). ...
- LeetCode() Symmetric Tree
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode ...
- leetcode:Symmetric Tree【Python版】
#error caused by:#1:{} 没有考虑None输入#2:{1,2,2} 没有控制h和t#3:{4,-57,-57,#,67,67,#,#,-97,-97} 没有考虑负号,将s从str变 ...
- 【LeetCode】Symmetric Tree 推断一棵树是否是镜像的
题目:Symmetric Tree <span style="font-size:18px;"><span style="font-size:18px; ...
随机推荐
- .net中将DataTable导出到word、Excel、txt、htm的方法
dt:DataTable strFile:fileName strExt:type private void GridExport(DataTable dt, string strFile, stri ...
- UITableView的简单总结与回顾
今天突发奇想的想对UItableView做一下汇总,感觉在编程中这个控件可以千变万化也是用的最多的一个了,下面就为大家简单总结下这个控件,也许还有不足,不过还是请各位不吝赐教了哈,那么我就开始了,我会 ...
- wlan0 Interface doesn't support scanning : Device or resource busy
Problem: wlan0 Interface doesn't support scanning : Device or resource busy. Solved Way: sudo ifcong ...
- 利用“参数赋值”防范SQL注入漏洞攻击
<<年轻,无权享受>————送给每一个看到此文的同僚们 在这无精打采的炎夏 我躺在阳台上房东的旧沙发 回想几个月来遇到的问题 我不禁内心开始慌张喘着粗气 还有大把时间去打拼 没有到只 ...
- oracle 存储过程返回结果集 (转载)
好久没上来了, 难道今天工作时间稍有空闲, 研究了一下oracle存储过程返回结果集. 配合oracle临时表, 使用存储过程来返回结果集的数据读取方式可以解决海量数据表与其他表的连接问题. 在存储过 ...
- 选中CheckBoxList的值放到TextBox中,再次选中从textBox中删除
当选中checkboxlist中的值,直接放到文本框中,在checkboxlist的SelectedIndexChanged事件下执行方法, //将选中的值放到文本框中 ...
- String.equals()
名称 说明 String.Equals(Obejecct) 确定String实例是否指 ...
- CSU 1335 高桥和低桥
开始队友说是线段树,看了看貌似也是,上手敲了个嵌套的线段树,O(nlognlogn)的复杂度果断tle了 TAT 思路:对h[i]排序,对每次涨水退水,先用二分查找,再用一个数组保存当前点之后所有点被 ...
- 用委托、匿名函数、Lambda的方式输出符合要求的数
最近看了一些博客,对委托和匿名函数和Lambda的方式有了一些更深的理解,在前人的基础上.我也写3个例子 using System; using System.Collections.Generic; ...
- 记事本创建servlet在tomcat中发布基本思路
在webapps中新建文件夹H,在其中再创建WEB-INF文件夹,在创建classes文件夹和web.xml文件,web.xml需要配置一下,classes文件夹中存放Servlet经编译过的clas ...