Path Sum II--LeetCode
来源:互联网 发布:意大利 世界杯 知乎 编辑:程序博客网 时间:2024/06/01 15:13
题目:
Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.
For example:Given the below binary tree and
sum = 22
,5 / \ 4 8 / / \ 11 13 4 / \ / \ 7 2 5 1
return
[ [5,4,11,2], [5,8,4,5]]
void helper(BinTree* root,int key,int cur,vector<int>& vec){if(root == NULL)return ;cur+=root->value;vec.push_back(root->value);if(root->left == NULL && root->right == NULL && cur == key){int i;for(i=0;i<vec.size();i++)cout<<vec[i]<<" ";cout<<endl;}if(root->left !=NULL){helper(root->left,key,cur,vec);vec.pop_back();}if(root->right !=NULL){helper(root->right,key,cur,vec);vec.pop_back();}}void PathSum(BinTree* root,int key){int cur=0;if(root== NULL)return ;vector<int> vec;helper(root,key,cur,vec);}
1 0
- LeetCode: Path Sum II
- LeetCode Path Sum II
- [Leetcode] Path Sum II
- LeetCode: Path Sum II
- [LeetCode] Path Sum II
- 【leetcode】Path Sum II
- [LeetCode]Path Sum II
- [Leetcode]Path Sum II
- [leetcode]Path Sum II
- Leetcode: Path Sum II
- LeetCode-Path Sum II
- [leetcode] Path Sum II
- LeetCode - Path Sum II
- [LeetCode] Path Sum II
- Leetcode Path Sum II
- LeetCode | Path Sum II
- 【leetcode】Path Sum II
- [LeetCode] Path Sum II
- JAVA学习笔记(五十八)- InetAddress类与URL
- Vivado实现纯逻辑开发——从最简单的开始
- 智能家居需求分析
- 在Linux主机上搭建SVN,用于同步提交修改,实现本地提交线上预览
- 新浪微博note
- Path Sum II--LeetCode
- 关键字final
- C++ typedef 类型前置声明
- 黑马程序员——java基础——两个排序,一个查找
- Python常用函数
- 【翻译自mos文章】闪回区和flashback database
- 第五周阅读程序二
- linux中的进程和线程
- ZOJ 1006