当前位置:网站首页>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;
}
边栏推荐
- U.S. Air Force Research Laboratory, "exploring the vulnerability and robustness of deep learning systems", the latest 85 page technical report in 2022
- 19.(arcgis api for js篇)arcgis api for js线采集(SketchViewModel)
- 预处理——插值
- Appx code signing Guide
- [MySQL] row sorting in MySQL
- A 股指数成分数据 API 数据接口
- 红米k40s root玩机笔记
- Delete data in SQL
- Top 50 hit industry in the first half of 2022
- ggplot 分面的细节调整汇总
猜你喜欢

枚举通用接口&枚举使用规范

Can the applet run in its own app and realize live broadcast and connection?

再AD 的 界面顶部(菜单栏)创建常用的快捷图标

ubuntu20安裝redisjson記錄

It's too convenient. You can complete the code release and approval by nailing it!

About Tolerance Intervals

Flutter3.0, the applet is not only run across mobile applications

亚像素级角点检测Opencv-cornerSubPix

Code quality management
![[development software] tilipa Developer Software](/img/b8/de2a1ea6474bb3f9b44e7ea01c441b.png)
[development software] tilipa Developer Software
随机推荐
HMS core machine learning service creates a new "sound" state of simultaneous interpreting translation, and AI makes international exchanges smoother
Preprocessing - interpolation
如何替换模型的骨干网络(backbone)
The latest 2022 review of "small sample deep learning image recognition"
SSL证书部署
我的勇敢对线之路--详细阐述,浏览器输入URL发生了什么
VHDL实现单周期CPU设计
海思万能平台搭建:颜色空间转换YUV2RGB
Can the applet run in its own app and realize live broadcast and connection?
GPT-3当一作自己研究自己,已投稿,在线蹲一个同行评议
维护万星开源向量数据库是什么体验
未来发展路线确认!数字经济、数字化转型、数据...这次会议很重要
Flutter3.0, the applet is not only run across mobile applications
QT opens a file and uses QFileDialog to obtain the file name, content, etc
自适应非欧表征广告检索系统AMCAD
21. (article ArcGIS API for JS) ArcGIS API for JS rectangular acquisition (sketchviewmodel)
代码质量管理
23.(arcgis api for js篇)arcgis api for js椭圆采集(SketchViewModel)
浅谈网络安全之文件上传
1200.Minimum Absolute Difference