当前位置:网站首页>leetcode-对称二叉树
leetcode-对称二叉树
2022-08-05 02:00:00 【qq_52025208】
题目描述:
给定一个二叉树,检查它是否是镜像对称的。
例如,二叉树 [1,2,2,3,4,4,3] 是对称的。
1
/
2 2
/ \ /
3 4 4 3
class Solution {
public boolean isSymmetric(TreeNode root) {
if(root == null) return true;
return isSymmetricChild(root.left,root.right);
}
public boolean isSymmetricChild(TreeNode s,TreeNode t) {
if(s == null && t == null) return true;
if(s== null && t != null || s != null && t == null) return false;
if(s.val != t.val) return false;
return isSymmetricChild(s.left,t.right)&&isSymmetricChild(s.right,t.left);
}
}
边栏推荐
- CPDA|运营人如何从负基础学会数据分析(SQL)
- pytorch的使用:使用神经网络进行气温预测
- source program in assembly language
- Residential water problems
- 释放技术创新引擎,英特尔携手生态合作伙伴推动智慧零售蓬勃发展
- oracle将restful接口封装到视图中
- 【存储】曙光存储DS800-G35 ISCSI各映射LUN给服务器
- [How to smash wool according to the music the couple listens to during the Qixi Festival] Does the background music affect the couple's choice of wine?
- [GYCTF2020]EasyThinking
- AI+小核酸药物|Eleven完成2200万美元种子轮融资
猜你喜欢
sql语句多字段多个值如何进行排序
Chapter 09 Use of Performance Analysis Tools [2. Index and Tuning] [MySQL Advanced]
海量服务实例动态化管理
直播预告|30分钟快速入门!来看可信分布式AI链桨的架构设计
如何发现一个有价值的 GameFi?
【MySQL系列】- LIKE查询 以%开头一定会让索引失效吗
tcp中的三次握手与四次挥手
Live playback including PPT download | Build Online Deep Learning based on Flink & DeepRec
如何基于OpenVINO POT工具简单实现对模型的量化压缩
[GYCTF2020]EasyThinking
随机推荐
Fragment visibility judgment
The use of pytorch: temperature prediction using neural networks
ExcelPatternTool: Excel表格-数据库互导工具
如何创建rpm包
使用SuperMap iDesktopX数据迁移工具迁移ArcGIS数据
树形查找(二叉查找树)
【Endnote】Word插入自定义形式的Endnote文献格式
DDOS攻击真的是无解吗?不!
Understand the recommendation system in one article: Recall 06: Two-tower model - model structure, training method, the recall model is a late fusion feature, and the sorting model is an early fusion
js中try...catch和finally的用法
详细全面的postman接口测试实战教程
开篇-开启全新的.NET现代应用开发体验
习题:选择结构(一)
如何逐步执行数据风险评估
Greenplum Database Fault Analysis - Why Does gpstart -a Return Failure After Version Upgrade?
source program in assembly language
".NET IoT from scratch" series
测试工作这么难找吗?今年32,失业2个月,大龄测试工程师接下来该拿什么养家?
Leetcode刷题——22. 括号生成
[Machine Learning] 21-day Challenge Study Notes (2)