当前位置:网站首页>力扣-相同的树
力扣-相同的树
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);
}
}
边栏推荐
- [Endnote] Word inserts a custom form of Endnote document format
- .Net C# 控制台 使用 Win32 API 创建一个窗口
- 第十四天&postman
- How do programmers without objects spend the Chinese Valentine's Day
- [Redis] Redis installation under Linux
- 如何模拟后台API调用场景,很细!
- Day Fourteen & Postman
- 如何看待自己的羞愧感
- EBS利用虚拟列及hint 提示优化sql案例一则
- 超越YOLO5-Face | YOLO-FaceV2正式开源Trick+学术点拉满
猜你喜欢
直播回放含 PPT 下载|基于 Flink & DeepRec 构建 Online Deep Learning
【七夕如何根据情侣倾听的音乐进行薅羊毛】背景音乐是否会影响情侣对酒的选择
Live playback including PPT download | Build Online Deep Learning based on Flink & DeepRec
程序员失眠时的数羊列表 | 每日趣闻
IJCAI2022 | DictBert:采用对比学习的字典描述知识增强的预训练语言模型
MySQL3
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
2022 EdgeX中国挑战赛8月3日即将盛大开幕
如何基于OpenVINO POT工具简单实现对模型的量化压缩
第十四天&postman
随机推荐
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
亚马逊云科技 + 英特尔 + 中科创达为行业客户构建 AIoT 平台
"Dilili, wait for the lights, wait for the lights", the prompt sound for safe production in the factory
fragment可见性判断
Leetcode刷题——22. 括号生成
如何看待自己的羞愧感
(17) 51 MCU - AD/DA conversion
Domain Driven Design - MDD
【MySQL series】- Does LIKE query start with % will make the index invalid?
使用SuperMap iDesktopX数据迁移工具迁移ArcGIS数据
汇编语言之源程序
[Unity Entry Plan] Handling of Occlusion Problems in 2D Games & Pseudo Perspective
Exploding the circle of friends, Alibaba produced billion-level concurrent design quick notes are too fragrant
Dotnet 6 Why does the network request not follow the change of the system network proxy and dynamically switch the proxy?
[Redis] Redis installation under Linux
原生js实现多选框全部选中和取消效果
MySQL3
方法重写与Object类
“配置”是把双刃剑,带你了解各种配置方法
pytorch的使用:卷积神经网络模块