当前位置:网站首页>[force buckle] the same tree
[force buckle] the same tree
2022-07-19 06:26:00 【Patrick star`】
100. Same tree - Power button (LeetCode)
subject :
Here are the root nodes of two binary trees p and q , Write a function to check whether the two trees are the same .
If two trees are the same in structure , And the nodes have the same value , They are the same .
Ideas :
Using recursive methods
If it's all empty return false
If one is empty and the other is not return false
If the values of two nodes are not equal ,return false
Judge whether the left subtree and the right subtree are the same
Code :
bool isSameTree(struct TreeNode* p, struct TreeNode* q){
if(p==NULL && q==NULL)
{
return true;
}
if(q&&!p)
{
return false;
}
if(p&&!q)
{
return false;
}
if(p->val != q->val)
{
return false;
}
bool ret1 = isSameTree(p->left,q->left);// Whether the left subtree is the same tree
bool ret2 = isSameTree(p->right,q->right);// Whether the right subtree is the same tree
return ret1 && ret2;
}边栏推荐
- Chrome browser settings [display the translation language icon in the upper right corner]
- ES聚合分析报错:“reason“ : “Text fields are not optimised for operations
- 【力扣】设计循环队列
- EOG-based eye movement detection and gaze estimation for an asynchronous virtual keyboard基于EOG的异步虚
- Triangle ranch (0/1 backpack)
- 数学基础课2_欧拉函数,线性筛,扩欧
- Introduction to easydarawin streaming media server
- Unity2D学习 Fox Game制作 过程1:基本的游戏角色控制,动画效果,镜头控制,物品收集,bug优化
- MCU single chip OTP
- 2021-11-10 micropyton tb6600 step drive class
猜你喜欢

Qt Creator闪退解决办法

Introduction to basic knowledge of Minio

Résoudre le problème de l'ambiguïté de la cible dans l'interaction de fixation 3D par l'estimation de la profondeur vor

Talking about several solutions of cross domain

Unity2D学习 Fox Game制作 过程1:基本的游戏角色控制,动画效果,镜头控制,物品收集,bug优化

解决:无法加载文件 C:\Program Files\.. 因为在此系统上禁止运行脚本...

mapping索引属性 & 创建索的操作

[antdv: Each record in table should have a unique `key` prop,or set `rowKey` to an unique.....
![[simple and fast] after startup, the desktop is normal, and the taskbar below is unresponsive / the mouse keeps turning](/img/65/fbb975491d4abd5d1babdf000513e2.png)
[simple and fast] after startup, the desktop is normal, and the taskbar below is unresponsive / the mouse keeps turning

通過VOR深度估計解决三維注視交互中的目標模糊問題
随机推荐
2022/07/14 学习笔记 (day07)数组
Antd is not defined
Where have all the older programmers gone?
EOG based eye movement detection and gaze estimation for an asynchronous virtual keyboard
Acwing game 59 (AK)
RestClient-多条件聚合
【力扣】相同的树
【力扣】复制带随机指针的链表
Knapsack with dependency, narrow sense (binary enumeration), broad sense (tree DP)
Interview review nth time
嵌入式C语言重点(const、static、voliatile、位运算)
Qt Creator闪退解决办法
Qtss constant
Eye tracking in virtual reality
2021-11-10 micropyton tb6600 step drive class
XOR-gun (位运算,思维,区间暴力)
最长括号匹配 (线性DP)
uboot 编译前的配置命令make config分析
带透明png转换成c数组
【力扣】用栈实现队列