当前位置:网站首页>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;
}
边栏推荐
- Open3D 网格滤波
- Depth analysis of compilation constants, classloader classes, and system class loaders
- Delete data in SQL
- Appx code signing Guide
- PHP lightweight Movie Video Search Player source code
- About Tolerance Intervals
- 【DPDK】dpdk样例源码解析之三:dpdk-l3fwd_001
- 19.(arcgis api for js篇)arcgis api for js线采集(SketchViewModel)
- 卡尔曼滤波-1
- VHDL实现单周期CPU设计
猜你喜欢

Under the tide of "going from virtual to real", Baidu AI Cloud is born from real
10 ways of interface data security assurance

24.(arcgis api for js篇)arcgis api for js点修改点编辑(SketchViewModel)

Confirm the future development route! Digital economy, digital transformation, data This meeting is very important

1200.Minimum Absolute Difference

Set WiFi automatic connection for raspberry pie

ggplot 分面的细节调整汇总

About Confidence Intervals

QT thread and other 01 concepts

函数重入、函数重载、函数重写自己理解
随机推荐
Top 50 hit industry in the first half of 2022
HMS core machine learning service creates a new "sound" state of simultaneous interpreting translation, and AI makes international exchanges smoother
CVPR 2022 best paper candidate | pip: six inertial sensors realize whole body dynamic capture and force estimation
Native MySQL
QT opens a file and uses QFileDialog to obtain the file name, content, etc
什么是 BA ?BA怎么样?BA和BI是什么关系?
SQL injection -day15
【mysql】mysql中行排序
The true face of function pointer in single chip microcomputer and the operation of callback function
22.(arcgis api for js篇)arcgis api for js圆采集(SketchViewModel)
腾讯云原生数据库TDSQL-C入选信通院《云原生产品目录》
Sorting operation partition, argpartition, sort, argsort in numpy
华为小米互“抄作业”
函数重入、函数重载、函数重写自己理解
C task expansion method
线性表的查找
24. (ArcGIS API for JS) ArcGIS API for JS point modification point editing (sketchviewmodel)
编译常量、ClassLoader类、系统类加载器深度探析
密码学系列之:在线证书状态协议OCSP详解
Ubuntu 20 installation des enregistrements redisjson