当前位置:网站首页>力扣-相同的树
力扣-相同的树
2022-08-05 02:00:00 【qq_52025208】
题目描述:给你两棵二叉树的根节点 p 和 q ,编写一个函数来检验这两棵树是否相同。
如果两个树在结构上相同,并且节点具有相同的值,则认为它们是相同的。
class Solution {
public boolean isSameTree(TreeNode p, TreeNode q) {
if(p == null && q != null || p != null && q == null ) {
return false;
}
if(p == null && q == null) {
return true;
}
if(p.val != q.val) {
return false;
}
return isSameTree(p.left,q.left)&&isSameTree(p.right,q.right);
}
}
边栏推荐
- Greenplum Database Fault Analysis - Why Does gpstart -a Return Failure After Version Upgrade?
- LPQ (local phase quantization) study notes
- 迅睿cms网站搬迁换了服务器后网站不能正常显示
- KingbaseES V8 GIS数据迁移方案(2. Kingbase GIS能力介绍)
- 亚马逊云科技携手中科创达为行业客户构建AIoT平台
- 刷爆朋友圈,Alibaba出品亿级并发设计速成笔记太香了
- Exploding the circle of friends, Alibaba produced billion-level concurrent design quick notes are too fragrant
- 程序员失眠时的数羊列表 | 每日趣闻
- 如何模拟后台API调用场景,很细!
- XMjs跨域问题解决
猜你喜欢

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

迁移学习——Distant Domain Transfer Learning

新来个技术总监,把DDD落地的那叫一个高级,服气

直播预告|30分钟快速入门!来看可信分布式AI链桨的架构设计

编译预处理等细节

js中try...catch和finally的用法

Method Overriding and Object Class

缺陷检测(图像处理部分)

海量服务实例动态化管理

Hypervisor related knowledge points
随机推荐
如何发现一个有价值的 GameFi?
Utilities 2022杭电多校第一场
在这个超连接的世界里,你的数据安全吗
Greenplum数据库故障分析——版本升级后gpstart -a为何返回失败
Xunrui cms website cannot be displayed normally after relocation and server change
CMS website construction process
.Net C# Console Create a window using Win32 API
【Endnote】Word插入自定义形式的Endnote文献格式
Greenplum数据库故障分析——能对数据库base文件夹进行软连接嘛?
SuperMap iDesktop.Net之布尔运算求交——修复含拓扑错误复杂模型
新来个技术总监,把DDD落地的那叫一个高级,服气
开篇-开启全新的.NET现代应用开发体验
Chapter 09 Use of Performance Analysis Tools [2. Index and Tuning] [MySQL Advanced]
Transfer Learning - Distant Domain Transfer Learning
软件测试技术之最有效的七大性能测试技术
(十七)51单片机——AD/DA转换
直播预告|30分钟快速入门!来看可信分布式AI链桨的架构设计
Jincang database KingbaseES V8 GIS data migration solution (3. Data migration based on ArcGIS platform to KES)
[Machine Learning] 21-day Challenge Study Notes (2)