当前位置:网站首页>力扣------路径总和 III
力扣------路径总和 III
2022-07-06 21:00:00 【qq_37760746】
/** * 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;
}
边栏推荐
- How to replace the backbone of the model
- Sorting operation partition, argpartition, sort, argsort in numpy
- 24. (ArcGIS API for JS) ArcGIS API for JS point modification point editing (sketchviewmodel)
- 图形化工具打包YOLOv5,生成可执行文件EXE
- A 股指数成分数据 API 数据接口
- . Net interface can be implemented by default
- The latest 2022 review of "small sample deep learning image recognition"
- 如何替换模型的骨干网络(backbone)
- 10 ways of interface data security assurance
- Experience design details
猜你喜欢
GPT-3当一作自己研究自己,已投稿,在线蹲一个同行评议
Clock in during winter vacation
枚举通用接口&枚举使用规范
10 ways of interface data security assurance
[security attack and Defense] how much do you know about serialization and deserialization?
Probability formula
Baidu map JS development, open a blank, bmapgl is not defined, err_ FILE_ NOT_ FOUND
接口数据安全保证的10种方式
On file uploading of network security
哈夫曼树基本概念
随机推荐
.net中 接口可以有默认实现了
CVPR 2022 best paper candidate | pip: six inertial sensors realize whole body dynamic capture and force estimation
GPT-3当一作自己研究自己,已投稿,在线蹲一个同行评议
2022.6.28
Que savez - vous de la sérialisation et de l'anti - séquence?
MySQL的存储引擎
[Dameng database] after backup and recovery, two SQL statements should be executed
Tencent cloud native database tdsql-c was selected into the cloud native product catalog of the Academy of communications and communications
SSL certificate deployment
10 ways of interface data security assurance
22. (ArcGIS API for JS) ArcGIS API for JS Circle Collection (sketchviewmodel)
Not All Points Are Equal Learning Highly Efficient Point-based Detectors for 3D LiDAR Point
Lab1 configuration script
Ubuntu20 installation redisjson record
R数据分析:cox模型如何做预测,高分文章复现
校招行测笔试-数量关系
Introduction to opensea platform developed by NFT trading platform (I)
【mysql】mysql中行排序
本机mysql
CMB's written test - quantitative relationship