当前位置:网站首页>力扣------路径总和 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;
}
边栏推荐
- Vernacular high concurrency (2)
- Code quality management
- Implementation steps of docker deploying mysql8
- SSL证书部署
- How to customize the shortcut key for latex to stop running
- 自适应非欧表征广告检索系统AMCAD
- codeforces每日5题(均1700)-第七天
- The latest 2022 review of "small sample deep learning image recognition"
- 什么是 BA ?BA怎么样?BA和BI是什么关系?
- Tencent cloud native database tdsql-c was selected into the cloud native product catalog of the Academy of communications and communications
猜你喜欢

编译常量、ClassLoader类、系统类加载器深度探析

R data analysis: how to predict Cox model and reproduce high score articles
Docker部署Mysql8的实现步骤

机器学习笔记 - 使用机器学习进行鸟类物种分类

哈夫曼树基本概念

代码质量管理

22.(arcgis api for js篇)arcgis api for js圆采集(SketchViewModel)

Mobile measurement and depth link platform - Branch

如何替换模型的骨干网络(backbone)

API data interface of A-share index component data
随机推荐
How to customize the shortcut key for latex to stop running
什么是 BA ?BA怎么样?BA和BI是什么关系?
Function reentry, function overloading and function rewriting are understood by yourself
机器学习笔记 - 使用机器学习进行鸟类物种分类
. Net interface can be implemented by default
Not All Points Are Equal Learning Highly Efficient Point-based Detectors for 3D LiDAR Point
Confirm the future development route! Digital economy, digital transformation, data This meeting is very important
VHDL实现单周期CPU设计
Index of MySQL
Native MySQL
编译常量、ClassLoader类、系统类加载器深度探析
Optimization cases of complex factor calculation: deep imbalance, buying and selling pressure index, volatility calculation
How to replace the backbone of the model
Preprocessing - interpolation
2022年上半年HIT行业TOP50
[dream database] add the task of automatically collecting statistical information
亚像素级角点检测Opencv-cornerSubPix
23. (ArcGIS API for JS) ArcGIS API for JS ellipse collection (sketchviewmodel)
注意力机制原理
22. (ArcGIS API for JS) ArcGIS API for JS Circle Collection (sketchviewmodel)