当前位置:网站首页>力扣------路径总和 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)
- About Estimation Statistics
- Native MySQL
- VHDL implementation of arbitrary size matrix multiplication
- VHDL implementation of arbitrary size matrix addition operation
- 卡尔曼滤波-1
- GPT-3当一作自己研究自己,已投稿,在线蹲一个同行评议
- [dream database] add the task of automatically collecting statistical information
- Function reentry, function overloading and function rewriting are understood by yourself
猜你喜欢
2022年上半年HIT行业TOP50
Que savez - vous de la sérialisation et de l'anti - séquence?
[leetcode] 700 and 701 (search and insert of binary search tree)
1200.Minimum Absolute Difference
Search of linear table
Open3D 网格滤波
ubuntu20安装redisjson记录
Mathematical induction and recursion
Introduction to opensea platform developed by NFT trading platform (I)
How to customize the shortcut key for latex to stop running
随机推荐
22. (ArcGIS API for JS) ArcGIS API for JS Circle Collection (sketchviewmodel)
Delete data in SQL
Que savez - vous de la sérialisation et de l'anti - séquence?
Tencent cloud native database tdsql-c was selected into the cloud native product catalog of the Academy of communications and communications
Mobile measurement and depth link platform - Branch
23. (ArcGIS API for JS) ArcGIS API for JS ellipse collection (sketchviewmodel)
Not All Points Are Equal Learning Highly Efficient Point-based Detectors for 3D LiDAR Point
About Tolerance Intervals
About Tolerance Intervals
Ubuntu 20 installation des enregistrements redisjson
HW-小记(二)
2022.6.28
19. (ArcGIS API for JS) ArcGIS API for JS line acquisition (sketchviewmodel)
25.(arcgis api for js篇)arcgis api for js线修改线编辑(SketchViewModel)
API data interface of A-share index component data
The true face of function pointer in single chip microcomputer and the operation of callback function
25. (ArcGIS API for JS) ArcGIS API for JS line modification line editing (sketchviewmodel)
Optimization cases of complex factor calculation: deep imbalance, buying and selling pressure index, volatility calculation
Adaptive non European advertising retrieval system amcad
华为小米互“抄作业”