当前位置:网站首页>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;
}
边栏推荐
- ggplot 分面的细节调整汇总
- Implementation steps of docker deploying mysql8
- 密码学系列之:在线证书状态协议OCSP详解
- Flutter3.0, the applet is not only run across mobile applications
- About Estimation Statistics
- SSL certificate deployment
- 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
- Free PHP online decryption tool source code v1.2
- Confirm the future development route! Digital economy, digital transformation, data This meeting is very important
- Tencent cloud native database tdsql-c was selected into the cloud native product catalog of the Academy of communications and communications
猜你喜欢
Que savez - vous de la sérialisation et de l'anti - séquence?
【安全攻防】序列化與反序列,你了解多少?
Sub pixel corner detection opencv cornersubpix
[MySQL] row sorting in MySQL
概率论公式
VHDL implementation of arbitrary size matrix addition operation
海思万能平台搭建:颜色空间转换YUV2RGB
2022年上半年HIT行业TOP50
RestClould ETL 社区版六月精选问答
Optimization cases of complex factor calculation: deep imbalance, buying and selling pressure index, volatility calculation
随机推荐
【C语言】 题集 of Ⅸ
Docker部署Mysql8的实现步骤
Kalman filter-1
如何替换模型的骨干网络(backbone)
如何自定义Latex停止运行的快捷键
A 股指数成分数据 API 数据接口
10 ways of interface data security assurance
codeforces每日5题(均1700)-第七天
Baidu map JS development, open a blank, bmapgl is not defined, err_ FILE_ NOT_ FOUND
腾讯云原生数据库TDSQL-C入选信通院《云原生产品目录》
图形化工具打包YOLOv5,生成可执行文件EXE
【安全攻防】序列化與反序列,你了解多少?
维护万星开源向量数据库是什么体验
自适应非欧表征广告检索系统AMCAD
VHDL implementation of arbitrary size matrix addition operation
[dpdk] dpdk sample source code analysis III: dpdk-l3fwd_ 001
Open3D 网格滤波
21.(arcgis api for js篇)arcgis api for js矩形采集(SketchViewModel)
Introduction to opensea platform developed by NFT trading platform (I)
My brave way to line -- elaborate on what happens when the browser enters the URL