当前位置:网站首页>437. Path sum III
437. Path sum III
2022-04-22 07:28:00 【yinhua405】
Given the root node of a binary tree root , And an integer targetSum , Find that the sum of the node values in the binary tree is equal to targetSum Of route Number of .
route You don't need to start at the root node , It doesn't need to end at the leaf node , But the path has to be down ( Only from parent node to child node ).
class Solution {
public:
void f(TreeNode* root, int targetSum,vector<int>sum,int &count)
{
if(nullptr ==root)
{
return;
}
vector<int> tmp;
for(auto it:sum)
{
tmp.push_back(it+root->val);
if(it+root->val == targetSum)
{
count++;
}
}
sum = tmp;
sum.push_back(root->val);
if(root->val == targetSum)
{
count++;
}
f(root->left, targetSum,sum,count);
f(root->right, targetSum,sum,count);
}
int pathSum(TreeNode* root, int targetSum) {
int ret=0;
vector<int>sum;
f(root,targetSum,sum,ret);
return ret;
}
};
版权声明
本文为[yinhua405]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220613324897.html
边栏推荐
- A. Weird Flecks, But OK (计算几何&三维最小圆覆盖)(2021年度训练联盟热身训练赛第一场)
- Yapi的安装与配置(转载)
- Codeforces Round #610 (Div. 2)
- LeetCode - 8 - (三数之和、Z字形变换、两数之和<链表>、盛最多水的容器、电话号码的字母组合)
- 15 · 全排列
- P1095 [NOIP2007 普及组] 守望者的逃离
- C language | array
- Idea does not display the run dashboard view window
- E.Figure Skating (字符串排序/签到) (2021年度训练联盟热身训练赛第五场 )
- Win10 modify command line default font
猜你喜欢

Redis Advanced

Redis進階

SQL复习语法笔记整理,新鲜出炉

Vivado generates and invokes EDF netlist files

最强操作符学习之路(C语言详解)

八大排序的思想及其代码

Relationship between A5 transceiver signal VOD and pre emphasis adjustment

链表难题记录一

What is the internal structure of stack frame?

(5) Use Navicat to create database data table and set ID auto increment
随机推荐
[DRC RTSTAT-1] Unrouted nets: 1 net(s) are unrouted
Cannot find interface mapping after updating HDF
363 · 接雨水
L2-004 这是二叉搜索树吗?(先序输入&判断搜索二叉树&后序输出)
LeetCode - 1 - (树的子结构、组合、螺旋矩阵、全排列<ⅠⅢ>)
Singleton pool, singleton bean, singleton mode
[number theory] congruence (V): multivariate linear congruence equation
【题解】洛谷P6186 [NOI Online #1 提高组] 冒泡排序:【冒泡排序】与【逆序对】问题
Codeforces Round #623
119 · 编辑距离
链表习题详解
SQL review, grammar notes, fresh out
(4) Character set in SQL Server (collation)
Yapi的安装与配置(转载)
384 · longest substring without repeated characters
最强数组学习之路
LeetCode - 2 - (括号生成、最长回文串、环形链表、反转链表、两两交换链表中的节点)
Why is the data stored in the leaf node of the non primary key index the primary key value
Unknown graphics extension:. 1 jpg. }
instanceof的使用说明及实例讲解