当前位置:网站首页>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);
}
};边栏推荐
- What is the difference between JSP and servlet?
- JS delete substring in string
- Go zero micro service practical series (VIII. How to handle tens of thousands of order requests per second)
- OpenPose的使用
- John blasting appears using default input encoding: UTF-8 loaded 1 password hash (bcrypt [blowfish 32/64 x3])
- DigiCert SSL证书支持中文域名申请吗?
- L'explosion de John utilise l'encodage d'entrée par défaut: UTF - 8 Loaded 1 password Hash (bcrypt [blowfish 32 / 64 X3])
- Connect Porsche and 3PL EDI cases
- Configure ARP table entry restrictions and port security based on the interface (restrict users' private access to fool switches or illegal host access)
- R and rstudio download and installation tutorial (super detailed)
猜你喜欢

Seven charts, learn to do valuable business analysis

Dgraph: large scale dynamic graph dataset

寒门再出贵子:江西穷县考出了省状元,做对了什么?

The macrogenome microbiome knowledge you want is all here (2022.7)

PWM breathing lamp

linux下配置Mysql授权某个用户远程访问,不受ip限制

七张图,学会做有价值的经营分析

几行代码搞定RPC服务注册和发现

Weili holdings listed on the Hong Kong Stock Exchange: with a market value of HK $500million, it contributed an IPO to Hubei

基于Impala的高性能数仓实践之执行引擎模块
随机推荐
【Leetcode】14. 最长公共前缀
js删除字符串中的子串
go-zero微服务实战系列(八、如何处理每秒上万次的下单请求)
綠竹生物沖刺港股:年期內虧損超5億 泰格醫藥與北京亦莊是股東
In MySQL and Oracle, the boundary and range of between and precautions when querying the date
几行代码搞定RPC服务注册和发现
IP地址转换地址段
Geoserver: publishing PostGIS data sources
Understand one article: four types of data index system
john爆破出现Using default input encoding: UTF-8 Loaded 1 password hash (bcrypt [Blowfish 32/64 X3])
宝宝巴士创业板IPO被终止:曾拟募资18亿 唐光宇控制47%股权
Easy language ABCD sort
Exploration and practice of integration of streaming and wholesale in jd.com
System Verilog implements priority arbiter
寒门再出贵子:江西穷县考出了省状元,做对了什么?
Leetcode1380: lucky numbers in matrix
<四> H264解码输出yuv文件
Seven charts, learn to do valuable business analysis
基于Impala的高性能数仓实践之执行引擎模块
易语言abcd排序