当前位置:网站首页>[tree] 100. Same tree
[tree] 100. Same tree
2022-07-25 11:23:00 【fatfatmomo】
Given two binary trees , Write a function to verify that they are the same .
If two trees are the same in structure , And the nodes have the same value , They are the same .
Method 1 : recursive
class Solution {
public:
bool isSameTree(TreeNode* p, TreeNode* q) {
bool state = true;
// It's all empty
if(p==nullptr&&q==nullptr)
{
return true;
}
// Only one is empty
if(p==nullptr||q==nullptr)
{
return false;
}
// None of them are empty
if(p->val==q->val)
{
return isSameTree(p->left,q->left)&isSameTree(p->right,q->right);
}
else
{
return false;
}
}
};
边栏推荐
- TPS calculation in performance test [Hangzhou multi tester] [Hangzhou multi tester _ Wang Sir]
- [information system project manager] thought map series essence summary
- 信息熵的定义
- HCIA experiment (07) comprehensive experiment
- [cloud enjoys freshness] community weekly · Vol 72 - the first opening ceremony of the 2022 Huawei developer competition in China was launched; Huawei cloud koomessage is in hot public beta
- Understand the life cycle and route jump of small programs
- Learn Luzhi PHP -- tp5.0 uses Chinese as an alias and reports "unsupported data expression"
- Reinforcement Learning 强化学习(三)
- Learn PHP -- phpstudy tips mysqld Exe: Error While Setting Value ‘NO_ ENGINE_ Solution of substitution error
- Hcip experiment (02)
猜你喜欢

What is MySQL transaction

MySQL | GROUP_CONCAT函数,将某一列的值用逗号拼接

A troubleshooting record of DirectShow playback problems

Only know that the preform is used to generate objects? See how I use unity to generate UI prefabs

Want to record your supernatural moments when playing games? Let's take a look at how to use unity screenshots

只知道预制体是用来生成物体的?看我如何使用Unity生成UI预制体

Mlx90640 infrared thermal imager temperature measurement module development notes (V)

HCIA experiment (07) comprehensive experiment

Learn NLP with Transformer (Chapter 7)

Ue4.26 source code version black screen problem of client operation when learning Wan independent server
随机推荐
Code representation learning: introduction to codebert and other related models
Learn NLP with Transformer (Chapter 6)
倍增Floyd「建议收藏」
从开源的视角,解析SAP经典ERP “三十年不用变”的架构设计
Guys, flick CDC table API, Mysql to MySQL, an application that can
There is a newline problem when passing shell script parameters \r
PostgreSQL踩坑 | ERROR: operator does not exist: uuid = character varying
Compressed list ziplist of redis
C# Newtonsoft.Json 高级用法
[servlet] request parsing
HDD杭州站全程体验有感
复习背诵整理版
Openstack skyline component installation
Syncronized lock upgrade process
Shell fourth day homework
How can you use unity without several plug-ins? Unity various plug-ins and tutorial recommendations
Tree dynamic programming
Learn NLP with Transformer (Chapter 5)
用Unity不会几个插件怎么能行?Unity各类插件及教程推荐
信息熵的定义