当前位置:网站首页>力扣------路径总和 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;
}
边栏推荐
- Sorting operation partition, argpartition, sort, argsort in numpy
- Codeworks 5 questions per day (1700 average) - day 7
- Graphical tools package yolov5 and generate executable files exe
- 链表面试常见题
- 25. (ArcGIS API for JS) ArcGIS API for JS line modification line editing (sketchviewmodel)
- Huawei and Xiaomi "copy each other"
- Search of linear table
- 卡尔曼滤波-1
- .net中 接口可以有默认实现了
- HW-小记(二)
猜你喜欢

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

VHDL实现任意大小矩阵乘法运算

RestClould ETL 社区版六月精选问答

Significance and measures of source code confidentiality

Adaptive non European advertising retrieval system amcad

Depth analysis of compilation constants, classloader classes, and system class loaders

Preprocessing - interpolation

codeforces每日5题(均1700)-第七天

Tencent cloud native database tdsql-c was selected into the cloud native product catalog of the Academy of communications and communications

Probability formula
随机推荐
华为小米互“抄作业”
When QT uses qtooltip mouse to display text, the picture of the button will also be displayed and the prompt text style will be modified
Hisilicon 3559 universal platform construction: RTSP real-time playback support
Machine learning notes - bird species classification using machine learning
Ubuntu 20 installation des enregistrements redisjson
MySQL的索引
RestClould ETL 社区版六月精选问答
接口数据安全保证的10种方式
[Dameng database] after backup and recovery, two SQL statements should be executed
20. (ArcGIS API for JS) ArcGIS API for JS surface collection (sketchviewmodel)
链表面试常见题
C# Task拓展方法
浅谈网络安全之文件上传
19.(arcgis api for js篇)arcgis api for js线采集(SketchViewModel)
GPT-3当一作自己研究自己,已投稿,在线蹲一个同行评议
22.(arcgis api for js篇)arcgis api for js圆采集(SketchViewModel)
Mathematical induction and recursion
[safe office and productivity application] Shanghai daoning provides you with onlyoffice download, trial and tutorial
复杂因子计算优化案例:深度不平衡、买卖压力指标、波动率计算
Construction of Hisilicon universal platform: color space conversion YUV2RGB