当前位置:网站首页>Sword finger offer 26 Substructure of tree
Sword finger offer 26 Substructure of tree
2022-07-02 17:12:00 【anieoo】
Original link : The finger of the sword Offer 26. The substructure of a tree

solution:
The code is mainly divided into two steps :
① adopt dfs Judge B Yes no A The subtree of the root node
② adopt isSubstructure Function for each A Traverse the nodes in
class Solution {
public:
bool isSubStructure(TreeNode* A, TreeNode* B) {
if(B == NULL || A == NULL) return false;
return dfs(A, B) || isSubStructure(A->left, B) || isSubStructure(A->right, B);
}
bool dfs(TreeNode *A, TreeNode *B) {
if(B == NULL)
return true;
if(A == NULL || A->val != B->val)
return false;
return dfs(A->left, B->left) && dfs(A->right, B->right);
}
};边栏推荐
- john爆破出現Using default input encoding: UTF-8 Loaded 1 password hash (bcrypt [Blowfish 32/64 X3])
- P6774 [NOI2020] 时代的眼泪(分块)
- Go zero micro service practical series (VIII. How to handle tens of thousands of order requests per second)
- 2322. Remove the minimum fraction of edges from the tree (XOR and & Simulation)
- 远程办公对我们的各方面影响心得 | 社区征文
- 福元医药上交所上市:市值105亿 胡柏藩身价超40亿
- Leetcode1380: lucky numbers in matrix
- QStyle实现自绘界面项目实战(二)
- 你想要的宏基因组-微生物组知识全在这(2022.7)
- <四> H264解码输出yuv文件
猜你喜欢

Configure MySQL under Linux to authorize a user to access remotely, which is not restricted by IP

绿竹生物冲刺港股:年期内亏损超5亿 泰格医药与北京亦庄是股东

剑指 Offer 25. 合并两个排序的链表

【Leetcode】13. 罗马数字转整数
![john爆破出現Using default input encoding: UTF-8 Loaded 1 password hash (bcrypt [Blowfish 32/64 X3])](/img/4c/ddf7f8085257d0eb8766dbec251345.png)
john爆破出現Using default input encoding: UTF-8 Loaded 1 password hash (bcrypt [Blowfish 32/64 X3])

linux安装postgresql + patroni 集群问题

亚马逊云科技 Community Builder 申请窗口开启
![L'explosion de John utilise l'encodage d'entrée par défaut: UTF - 8 Loaded 1 password Hash (bcrypt [blowfish 32 / 64 X3])](/img/4c/ddf7f8085257d0eb8766dbec251345.png)
L'explosion de John utilise l'encodage d'entrée par défaut: UTF - 8 Loaded 1 password Hash (bcrypt [blowfish 32 / 64 X3])

Go zero micro service practical series (VIII. How to handle tens of thousands of order requests per second)

【Leetcode】14. Longest Common Prefix
随机推荐
JS delete substring in string
LeetCode 6. Zigzag transformation (n-shaped transformation)
What is generics- Introduction to generics
关于举办科技期刊青年编辑沙龙——新时代青年编辑应具备的能力及提升策略的通知...
Cell: Tsinghua Chenggong group revealed an odor of skin flora. Volatiles promote flavivirus to infect the host and attract mosquitoes
go-zero微服务实战系列(八、如何处理每秒上万次的下单请求)
13、Darknet YOLO3
jsp 和 servlet 有什么区别?
Hard core! One configuration center for 8 classes!
How to transfer business data with BorgWarner through EDI?
基于多元时间序列对高考预测分析案例
Notice on holding a salon for young editors of scientific and Technological Journals -- the abilities and promotion strategies that young editors should have in the new era
社交元宇宙平台Soul冲刺港股:年营收12.8亿 腾讯是股东
IP地址转换地址段
国内比较好的OJ平台[通俗易懂]
綠竹生物沖刺港股:年期內虧損超5億 泰格醫藥與北京亦莊是股東
pwm呼吸灯
Kubernetes three open interfaces first sight
【Leetcode】14. Longest Common Prefix
LeetCode 3. Longest substring without duplicate characters