当前位置:网站首页>Force buckle ----- path sum III
Force buckle ----- path sum III
2022-07-07 03:51:00 【qq_ thirty-seven million seven hundred and sixty thousand seven】
/** * 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;
}
边栏推荐
- Free PHP online decryption tool source code v1.2
- Arduino droplet detection
- QT thread and other 01 concepts
- 太方便了,钉钉上就可完成代码发布审批啦!
- What about SSL certificate errors? Solutions to common SSL certificate errors in browsers
- .net中 接口可以有默认实现了
- [leetcode] 700 and 701 (search and insert of binary search tree)
- RestClould ETL 社区版六月精选问答
- Cryptography series: detailed explanation of online certificate status protocol OCSP
- SSL certificate deployment
猜你喜欢
随机推荐
VHDL实现单周期CPU设计
21. (article ArcGIS API for JS) ArcGIS API for JS rectangular acquisition (sketchviewmodel)
Gpt-3 is a peer review online when it has been submitted for its own research
函数重入、函数重载、函数重写自己理解
ggplot 分面的细节调整汇总
R数据分析:cox模型如何做预测,高分文章复现
Probability formula
卡尔曼滤波-1
QT 项目 表格新建列名称设置 需求练习(找数组消失的数字、最大值)
Open3D 网格滤波
pip只下载不安装
[leetcode] 700 and 701 (search and insert of binary search tree)
QT 使用QToolTip 鼠标放上去显示文字时会把按钮的图片也显示了、修改提示文字样式
Vernacular high concurrency (2)
19. (ArcGIS API for JS) ArcGIS API for JS line acquisition (sketchviewmodel)
Set static IP for raspberry pie
Construction of Hisilicon universal platform: color space conversion YUV2RGB
Tencent cloud native database tdsql-c was selected into the cloud native product catalog of the Academy of communications and communications
CMB's written test - quantitative relationship
Hisilicon 3559 universal platform construction: RTSP real-time playback support