当前位置:网站首页>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;
}
边栏推荐
- 21.(arcgis api for js篇)arcgis api for js矩形采集(SketchViewModel)
- Free PHP online decryption tool source code v1.2
- 25.(arcgis api for js篇)arcgis api for js线修改线编辑(SketchViewModel)
- Enumeration general interface & enumeration usage specification
- Tencent cloud native database tdsql-c was selected into the cloud native product catalog of the Academy of communications and communications
- About Tolerance Intervals
- 机器学习笔记 - 使用机器学习进行鸟类物种分类
- 自适应非欧表征广告检索系统AMCAD
- Under the tide of "going from virtual to real", Baidu AI Cloud is born from real
- VHDL实现任意大小矩阵加法运算
猜你喜欢

About Tolerance Intervals

Probability formula

链表面试常见题

How to customize the shortcut key for latex to stop running

Function reentry, function overloading and function rewriting are understood by yourself

About Confidence Intervals

20.(arcgis api for js篇)arcgis api for js面采集(SketchViewModel)

亚像素级角点检测Opencv-cornerSubPix

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

Graphical tools package yolov5 and generate executable files exe
随机推荐
Calculation of time and space complexity (notes of runners)
qt-线程等01概念
Can the applet run in its own app and realize live broadcast and connection?
C# Task拓展方法
【安全攻防】序列化与反序列,你了解多少?
Adaptive non European advertising retrieval system amcad
2022年上半年HIT行业TOP50
C task expansion method
codeforces每日5题(均1700)-第七天
pip只下载不安装
PIP download only, not install
GPT-3当一作自己研究自己,已投稿,在线蹲一个同行评议
海思万能平台搭建:颜色空间转换YUV2RGB
枚举通用接口&枚举使用规范
Depth analysis of compilation constants, classloader classes, and system class loaders
【安全攻防】序列化與反序列,你了解多少?
[security attack and Defense] how much do you know about serialization and deserialization?
图形化工具打包YOLOv5,生成可执行文件EXE
ERROR: Could not build wheels for pycocotools which use PEP 517 and cannot be installed directly
Tencent cloud native database tdsql-c was selected into the cloud native product catalog of the Academy of communications and communications