博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
LeetCode - Refresh - Path Sum II
阅读量:6981 次
发布时间:2019-06-27

本文共 1093 字,大约阅读时间需要 3 分钟。

Same with I

1 /** 2  * Definition for binary tree 3  * struct TreeNode { 4  *     int val; 5  *     TreeNode *left; 6  *     TreeNode *right; 7  *     TreeNode(int x) : val(x), left(NULL), right(NULL) {} 8  * }; 9  */10 class Solution {11 public:12     void getSum(vector
> &result, vector
current, TreeNode *root, int sum, int target) {13 if (!root) return;14 sum += root->val;15 current.push_back(root->val);16 if (!root->left && !root->right && sum == target) {17 result.push_back(current);18 return;19 }20 getSum(result, current, root->left, sum, target);21 getSum(result, current, root->right, sum, target);22 }23 vector
> pathSum(TreeNode *root, int sum) {24 vector
> result;25 getSum(result, vector
(), root, 0, sum);26 return result;27 }28 };

 

转载于:https://www.cnblogs.com/shuashuashua/p/4355903.html

你可能感兴趣的文章
日志分析工具splunt
查看>>
元素宽高的获取
查看>>
SQLSERVER存储过程基本语法使用
查看>>
sql server时间转换
查看>>
CDH大数据集群安全风险汇总
查看>>
数据结构实验之链表一:顺序建立链表
查看>>
docker Rails Permission denied @ dir_s_mkdir
查看>>
【二分答案】【最短路】bzoj1614 [Usaco2007 Jan]Telephone Lines架设电话线
查看>>
【贪心】Google Code Jam Round 1A 2018 Waffle Choppers
查看>>
【转载】【贪心】各种覆盖问题
查看>>
HDU 6051 - If the starlight never fade | 2017 Multi-University Training Contest 2
查看>>
insert into与insert ignore以及replace into的区别
查看>>
【网络流24题】最小路径覆盖问题
查看>>
java分享第五天(数组)
查看>>
数组与纠结的排序篇
查看>>
Linux命令-安装zip和unzip命令
查看>>
day03-字符编码与转换
查看>>
JS+CSS控制左右切换鼠标可控的无缝图片滚动代码
查看>>
C# 实现HTML转换成图片的方法
查看>>
访问本班同学的博客
查看>>