当前位置:网站首页>[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;
}边栏推荐
- 解决:无法加载文件 C:\Program Files\.. 因为在此系统上禁止运行脚本...
- 用头部运动学习无姿态注视偏差
- Solutions to slow transmission speed of FileZilla virtual machine
- 浅谈跨域的几种解决方案
- Acwing game 57 (AK)
- Low power LDO linear regulator IC
- 有依赖的背包,狭义(二进制枚举),广义(树形dp)
- Addition and subtraction of busybox date time
- 谷歌浏览器不能手动修改cookies,cookie报红标红
- Qtss constant
猜你喜欢

面试复习第N次

2022/07/12 学习笔记 (day05)循环

你的企业最适合哪种深度学习?
![[detailed tutorial installation] [configuration] auxiliary plug-ins about eslint in vscode](/img/d4/31272772b96d3e2f702da74478fd95.png)
[detailed tutorial installation] [configuration] auxiliary plug-ins about eslint in vscode

Qt Creator闪退解决办法

Positional change of the eyeball during eye movements: evidence of translational movement

处理中文分词 ik分词器以及拓展和停止字典

Introduction to Darwin streaming server

2022/07/14 learning notes (day07) array

自下而上和自上而下的注意力:不同的过程和重叠的神经系统 2014sci
随机推荐
Ehab the xorcist (XOR property, construction)
DSL实现Metrics 聚合
面试复习第N次
通過VOR深度估計解决三維注視交互中的目標模糊問題
使用候选选择从人类注视中学习视频显著性
LeetCode字符串
RestAPI实现聚合(黑马教程)
Interview review nth time
Cable TV network (tree grouping)
Leetcode tree
mapping索引属性 & 创建索的操作
Solve cannot read properties of null (reading 'pickalgorithm')
浅谈跨域的几种解决方案
vscode one dark和c扩展变量颜色冲突 设置settings.json如下即可
【力扣】二叉树的前序遍历
Single table query, add, update and delete data
有依赖的背包,狭义(二进制枚举),广义(树形dp)
Addition and subtraction of busybox date time
Basic mathematics course 2_ Euler function, linear sieve, extended Euler
【力扣】括号匹配