当前位置:网站首页>力扣------路径总和 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;
}
边栏推荐
- 2022夏每日一题(一)
- Principle of attention mechanism
- HW-小记(二)
- Sorting operation partition, argpartition, sort, argsort in numpy
- 25. (ArcGIS API for JS) ArcGIS API for JS line modification line editing (sketchviewmodel)
- 22. (ArcGIS API for JS) ArcGIS API for JS Circle Collection (sketchviewmodel)
- R数据分析:cox模型如何做预测,高分文章复现
- 大白话高并发(二)
- Machine learning notes - bird species classification using machine learning
- CVPR 2022 best paper candidate | pip: six inertial sensors realize whole body dynamic capture and force estimation
猜你喜欢
Principle of attention mechanism
亚像素级角点检测Opencv-cornerSubPix
25. (ArcGIS API for JS) ArcGIS API for JS line modification line editing (sketchviewmodel)
Adaptive non European advertising retrieval system amcad
接口数据安全保证的10种方式
Probability formula
codeforces每日5题(均1700)-第七天
Enumeration general interface & enumeration usage specification
19. (ArcGIS API for JS) ArcGIS API for JS line acquisition (sketchviewmodel)
RestClould ETL 社区版六月精选问答
随机推荐
VHDL implementation of arbitrary size matrix multiplication
[untitled]
QT item table new column name setting requirement exercise (find the number and maximum value of the array disappear)
SSL certificate deployment
Top 50 hit industry in the first half of 2022
[C language] question set of IX
qt-线程等01概念
1200.Minimum Absolute Difference
VHDL implementation of arbitrary size matrix addition operation
It's too convenient. You can complete the code release and approval by nailing it!
Codeworks 5 questions per day (1700 average) - day 7
Probability formula
Kalman filter-1
pip只下载不安装
【开发软件】 tilipa开发者软件
RestClould ETL 社区版六月精选问答
About Confidence Intervals
Principle of attention mechanism
ubuntu20安装redisjson记录
22. (ArcGIS API for JS) ArcGIS API for JS Circle Collection (sketchviewmodel)