当前位置:网站首页>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;
}
边栏推荐
- Flutter3.0, the applet is not only run across mobile applications
- ubuntu20安裝redisjson記錄
- 我的勇敢对线之路--详细阐述,浏览器输入URL发生了什么
- Can the applet run in its own app and realize live broadcast and connection?
- Confirm the future development route! Digital economy, digital transformation, data This meeting is very important
- 10 ways of interface data security assurance
- 小程序能运行在自有App中,且实现直播和连麦?
- QT 项目 表格新建列名称设置 需求练习(找数组消失的数字、最大值)
- 25. (ArcGIS API for JS) ArcGIS API for JS line modification line editing (sketchviewmodel)
- Machine learning notes - bird species classification using machine learning
猜你喜欢

Search of linear table

25.(arcgis api for js篇)arcgis api for js线修改线编辑(SketchViewModel)

About Confidence Intervals

海思3559万能平台搭建:RTSP实时播放的支持

20.(arcgis api for js篇)arcgis api for js面采集(SketchViewModel)

QT 打开文件 使用 QFileDialog 获取文件名称、内容等

Open3D 网格滤波

概率论公式

注意力机制原理
![[dpdk] dpdk sample source code analysis III: dpdk-l3fwd_ 001](/img/f6/dced69ea36fc95ef84bb546c56dd91.png)
[dpdk] dpdk sample source code analysis III: dpdk-l3fwd_ 001
随机推荐
QT 项目 表格新建列名称设置 需求练习(找数组消失的数字、最大值)
MySQL的索引
QT thread and other 01 concepts
Calculation of time and space complexity (notes of runners)
Kalman filter-1
Probability formula
Hisilicon 3559 universal platform construction: RTSP real-time playback support
About Confidence Intervals
Open3d mesh filtering
How to replace the backbone of the model
复杂因子计算优化案例:深度不平衡、买卖压力指标、波动率计算
What is the experience of maintaining Wanxing open source vector database
Open3D 网格滤波
Top 50 hit industry in the first half of 2022
【C语言】 题集 of Ⅸ
Sorting operation partition, argpartition, sort, argsort in numpy
校招行测笔试-数量关系
Depth analysis of compilation constants, classloader classes, and system class loaders
SQL injection -day15
枚举通用接口&枚举使用规范