[leetcode] 113. Path Sum II (Medium)
跟112多了一点就是保存路径
依然用dfs,多了两个vector保存路径
Runtime: 16 ms, faster than 16.09% of C++
class Solution
{
public:
vector<vector<int>> res;
vector<int> temp;
vector<vector<int>> pathSum(TreeNode *root, int sum)
{
dfs(root,temp,,sum);
return res;
}
void dfs(TreeNode *root, vector<int> cur, int total, int sum)
{
if (root == NULL)
return;
total += root->val;
cur.push_back(root->val);
if (root->left == NULL && root->right == NULL)
{
if (total == sum)
{
res.push_back(cur);
}
return;
}
if (root->left)
dfs(root->left, cur, total, sum);
if (root->right)
dfs(root->right, cur, total, sum);
}
};
[leetcode] 113. Path Sum II (Medium)的更多相关文章
- [LeetCode] 113. Path Sum II ☆☆☆(二叉树所有路径和等于给定的数)
LeetCode 二叉树路径问题 Path SUM(①②③)总结 Path Sum II leetcode java 描述 Given a binary tree and a sum, find al ...
- [LeetCode] 113. Path Sum II 路径和 II
Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given su ...
- [LeetCode] 113. Path Sum II 二叉树路径之和之二
Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given su ...
- leetcode 113. Path Sum II (路径和) 解题思路和方法
Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given su ...
- LeetCode 113. Path Sum II路径总和 II (C++)
题目: Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the give ...
- Leetcode 113. Path Sum II
Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given su ...
- leetcode 113 Path Sum II ----- java
Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given su ...
- [leetcode]113. Path Sum II路径和(返回路径)
Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given su ...
- Java for LeetCode 113 Path Sum II
Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given su ...
随机推荐
- Delphi事件的广播
原文地址:Delphi事件的广播 转作者:MondaySoftware 明天就是五一节了,辛苦了好几个月,借此机会应该尽情放松一番.可是想到Blog好久没有写文章,似乎缺些什么似的.这几个月来在项目中 ...
- 移动Web - 响应式布局开篇
用到的工具: FireFox浏览器 Sublime Text 2 响应式布局定义: 2010年,Ethan Marcotte提出,可查看原文: 通俗地讲就是:百份比布局,根据不同设备显示不同布局: 这 ...
- 网络软件,BA File,Disk,Photo,BackupTools等等(Mac版)
Auto FTP Manager 6.01Crossworld CrossFTP Enterprise v1.97.7 http://www.airexplorer.net/en/index.phpC ...
- 阻止系统自动睡眠的小软件,附C#制作过程(执行SetThreadExecutionState API函数,让系统误判)
因为有时下载东西的时候,不想让电脑自动深入睡眠,所以就开启了离开模式.这样不但不节能环保,而且到真正想要睡眠的时候就是一翻蛋疼. 改过自新,关闭了离开模式,同时无操作30分钟后也会进入睡眠模式.但是在 ...
- spring boot之security
上一节的时候,我们打开了springboot的端点,有一些数据是非常敏感的,比如/shutdown. 这一节,我们要给一些敏感信息加上权限控制. spring boot本身的security模块就很好 ...
- MySQL批量更新一个字段的值为随机数
$arr = []; $str = ''; for ($i=0; $i < 2660; ++$i) { $str .= " WHEN ".$i." THEN &qu ...
- Git 本地仓库(使用小乌龟进行操作,一个人开发)
一.首先在本地创建版本库 创建成功最明显的特征是该目录下存在一个隐藏文件夹(.git) 前提:已设置显示隐藏文件 三种方式: 1.Git GUI Here(右击) 2.Git Bash Here(右击 ...
- C语言-main方法的两个参数是干什么的?
大家都知道C语言的main方法怎么写的吧!但你们知道mian方法里的参数的含义吗? 代码如下: int main(int argc,char *argv[]){ //argc是传进的参数个数 //ar ...
- C语言之父Dennis Ritchie告诉你:如何成为世界上最好的程序员?
文/Ohans Emmanuel 译/网易云信 想要阅读更多技术干货文章,欢迎关注网易云信博客. 了解网易云信,来自网易核心架构的通信与视频云服务. 我不知道如何成为世界上最好的程序员.但是,我们可以 ...
- NoSQL数据库兴起
前言 近几年NoSQL数据库兴起,各种新的产品层出不穷,在此学习下NoSQL的基本理论,并认识下常见的NoSQL数据库. 一 NoSQL数据库兴起的原因 随着大数据技术兴起和Web2.0时代的到来.传 ...