当前位置:网站首页>力扣-相同的树
力扣-相同的树
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);
}
}
边栏推荐
- iNFTnews | What can NFTs bring to the sports industry and fans?
- ExcelPatternTool: Excel table-database mutual import tool
- [GYCTF2020]EasyThinking
- day14--postman interface test
- 网络安全与元宇宙:找出薄弱环节
- GC高德坐标和百度坐标转换
- "Dilili, wait for the lights, wait for the lights", the prompt sound for safe production in the factory
- PHP技能评测
- 一文看懂推荐系统:召回06:双塔模型——模型结构、训练方法,召回模型是后期融合特征,排序模型是前期融合特征
- 【机器学习】21天挑战赛学习笔记(二)
猜你喜欢

Three handshake and four wave in tcp

Xunrui cms website cannot be displayed normally after relocation and server change

day14--postman interface test

.Net C# Console Create a window using Win32 API

Why is this problem reported when installing oracle11

编译预处理等细节

Transfer Learning - Distant Domain Transfer Learning

迁移学习——Distant Domain Transfer Learning

【Word】Word公式导出PDF后出现井号括号#()错误

KingbaseES V8 GIS data migration solution (2. Introduction to the capabilities of Kingbase GIS)
随机推荐
方法重写与Object类
【Unity入门计划】2D游戏中遮挡问题的处理方法&伪透视
Jincang database KingbaseES V8 GIS data migration solution (3. Data migration based on ArcGIS platform to KES)
测试工作这么难找吗?今年32,失业2个月,大龄测试工程师接下来该拿什么养家?
“嘀哩哩,等灯等灯”,工厂安全生产的提示音
迅睿cms网站搬迁换了服务器后网站不能正常显示
Hypervisor related knowledge points
ExcelPatternTool: Excel表格-数据库互导工具
PHP Skills Assessment
Tree search (bintree)
LPQ (local phase quantization) study notes
Why is this problem reported when installing oracle11
【Word】Word公式导出PDF后出现井号括号#()错误
source program in assembly language
如何模拟后台API调用场景,很细!
PHP技能评测
如何创建rpm包
迁移学习——Distant Domain Transfer Learning
sql语句多字段多个值如何进行排序
【存储】曙光存储DS800-G35 ISCSI各映射LUN给服务器