当前位置:网站首页>[树] 100. 相同的树
[树] 100. 相同的树
2022-07-25 10:27:00 【fatfatmomo】
给定两个二叉树,编写一个函数来检验它们是否相同。
如果两个树在结构上相同,并且节点具有相同的值,则认为它们是相同的。
方法一:递归
class Solution {
public:
bool isSameTree(TreeNode* p, TreeNode* q) {
bool state = true;
//都空
if(p==nullptr&&q==nullptr)
{
return true;
}
//仅一个为空
if(p==nullptr||q==nullptr)
{
return false;
}
//均不为空
if(p->val==q->val)
{
return isSameTree(p->left,q->left)&isSameTree(p->right,q->right);
}
else
{
return false;
}
}
};
边栏推荐
- What is MySQL transaction
- HCIA experiment (06)
- Signal integrity (SI) power integrity (PI) learning notes (XXXIV) 100 rules of thumb for estimating signal integrity effects
- Gan, why '𠮷 𠮷'.Length== 3 ??
- HCIP(11)
- 【flask高级】结合源码解决flask经典报错:Working outside of application context
- The University of Gottingen proposed clipseg: a model that can perform three segmentation tasks simultaneously using text and image prompts
- 最详细的mysql索引解析(文末附赠思维导图)
- [flask advanced] solve the classic error reporting of flask by combining the source code: working outside of application context
- HDD Hangzhou station full experience
猜你喜欢

Esp8266 uses drv8833 drive board to drive N20 motor

企业实践开源的动机

Hcip experiment (01)

Reinforcement Learning 强化学习(三)

【flask高级】结合源码详解flask的运行机制(出入栈)
Learn NLP with Transformer (Chapter 4)

HCIA实验(08)

Flask框架——消息闪现

The practice of asynchronous servlet in image service

Ue4.26 source code version black screen problem of client operation when learning Wan independent server
随机推荐
How to notify users of wechat applet version update?
Probe into Druid query timeout configuration → who is the querytimeout of datasource and jdbctemplate effective?
[Blue Bridge Cup training 100 questions] scratch Taiji diagram Blue Bridge Cup scratch competition special prediction programming question centralized training simulation exercise question No. 22
Learn NLP with Transformer (Chapter 6)
Google Earth engine -- Statistics on the frequency of land classification year by year
Motivation of enterprises to practice open source
How to optimize the performance when the interface traffic increases suddenly?
软件测试技术之跨平台的移动端UI自动化测试(上)
学习路之PHP--Phpstudy 提示 Mysqld.Exe: Error While Setting Value ‘NO_ENGINE_SUBSTITUTION 错误的解决办法
Learn NLP with Transformer (Chapter 5)
ESP8266 使用 DRV8833驱动板驱动N20电机
一文读懂小程序的生命周期和路由跳转
HCIP (01)
NowCoderTOP12-16——持续更新ing
HCIA experiment (08)
30000 word express Servlet
Flask框架——Flask-WTF表单:数据验证、CSRF保护
AI system frontier dynamics issue 43: ONEFLOW V0.8.0 officially released; GPU finds human brain connections; AI doctoral online crowdfunding research topic
SQL语言(一)
Learn NLP with Transformer (Chapter 3)