当前位置:网站首页>Force buckle ----- path sum III
Force buckle ----- path sum III
2022-07-07 03:51:00 【qq_ thirty-seven million seven hundred and sixty thousand seven】

/** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */
int count;
void sum(struct TreeNode* root, int targetSum,long int nowsum){
if(nowsum==targetSum){
count++;
}
if(root->left){
nowsum=nowsum+root->left->val;
sum(root->left,targetSum,nowsum);
nowsum=nowsum-root->left->val;
}
if(root->right){
nowsum=nowsum+root->right->val;
sum(root->right,targetSum,nowsum);
nowsum=nowsum-root->right->val;
}
}
void dfs(struct TreeNode* root, int targetSum){
long int nowsum=0;
nowsum=nowsum+root->val;
sum(root, targetSum,nowsum);
if(root->left){
dfs(root->left,targetSum);
}
if(root->right){
dfs(root->right,targetSum);
}
}
int pathSum(struct TreeNode* root, int targetSum){
count=0;
if(!root){
return count;
}
dfs(root,targetSum);
return count;
}
边栏推荐
- Delete data in SQL
- 24.(arcgis api for js篇)arcgis api for js点修改点编辑(SketchViewModel)
- Que savez - vous de la sérialisation et de l'anti - séquence?
- 腾讯云原生数据库TDSQL-C入选信通院《云原生产品目录》
- VHDL implementation of arbitrary size matrix multiplication
- Set static IP for raspberry pie
- My brave way to line -- elaborate on what happens when the browser enters the URL
- 密码学系列之:在线证书状态协议OCSP详解
- 链表面试常见题
- [development software] tilipa Developer Software
猜你喜欢

Restcloud ETL Community Edition June featured Q & A

23.(arcgis api for js篇)arcgis api for js椭圆采集(SketchViewModel)
Implementation steps of docker deploying mysql8

如何自定义Latex停止运行的快捷键

Ubuntu 20 installation des enregistrements redisjson

Not All Points Are Equal Learning Highly Efficient Point-based Detectors for 3D LiDAR Point

2022.6.28

24.(arcgis api for js篇)arcgis api for js点修改点编辑(SketchViewModel)
![[MySQL] row sorting in MySQL](/img/97/8a451fa62796838e11242c86eecd8d.png)
[MySQL] row sorting in MySQL

Appx code signing Guide
随机推荐
VHDL实现单周期CPU设计
CMB's written test - quantitative relationship
Search of linear table
MySQL的存储引擎
海思3559万能平台搭建:RTSP实时播放的支持
【DPDK】dpdk样例源码解析之三:dpdk-l3fwd_001
Probability formula
[MySQL] row sorting in MySQL
[C language] question set of IX
Confirm the future development route! Digital economy, digital transformation, data This meeting is very important
1200.Minimum Absolute Difference
MySQL的索引
Que savez - vous de la sérialisation et de l'anti - séquence?
RestClould ETL 社区版六月精选问答
VHDL实现任意大小矩阵加法运算
21.(arcgis api for js篇)arcgis api for js矩形采集(SketchViewModel)
23. (ArcGIS API for JS) ArcGIS API for JS ellipse collection (sketchviewmodel)
Under the tide of "going from virtual to real", Baidu AI Cloud is born from real
First understand the principle of network
太方便了,钉钉上就可完成代码发布审批啦!