当前位置:网站首页>力扣------路径总和 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;
}
边栏推荐
- Create applet from 0
- . Net interface can be implemented by default
- Top 50 hit industry in the first half of 2022
- QT 使用QToolTip 鼠标放上去显示文字时会把按钮的图片也显示了、修改提示文字样式
- 注意力机制原理
- GPT-3当一作自己研究自己,已投稿,在线蹲一个同行评议
- 10 ways of interface data security assurance
- How to replace the backbone of the model
- 2022夏每日一题(一)
- Preprocessing - interpolation
猜你喜欢

1200.Minimum Absolute Difference

Hisilicon 3559 universal platform construction: RTSP real-time playback support

25. (ArcGIS API for JS) ArcGIS API for JS line modification line editing (sketchviewmodel)

如何自定义Latex停止运行的快捷键

HMS core machine learning service creates a new "sound" state of simultaneous interpreting translation, and AI makes international exchanges smoother

Code quality management

未来发展路线确认!数字经济、数字化转型、数据...这次会议很重要

A 股指数成分数据 API 数据接口

QT thread and other 01 concepts

PHP lightweight Movie Video Search Player source code
随机推荐
HW-小记(二)
【安全攻防】序列化与反序列,你了解多少?
VHDL implementation of arbitrary size matrix addition operation
Construction of Hisilicon universal platform: color space conversion YUV2RGB
Calculation of time and space complexity (notes of runners)
It's too convenient. You can complete the code release and approval by nailing it!
Huawei and Xiaomi "copy each other"
【开发软件】 tilipa开发者软件
[untitled]
预处理——插值
Top 50 hit industry in the first half of 2022
About Tolerance Intervals
Principle of attention mechanism
19. (ArcGIS API for JS) ArcGIS API for JS line acquisition (sketchviewmodel)
Enumeration general interface & enumeration usage specification
Introduction to opensea platform developed by NFT trading platform (I)
Delete data in SQL
How to customize the shortcut key for latex to stop running
VHDL实现任意大小矩阵加法运算
My brave way to line -- elaborate on what happens when the browser enters the URL