[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 ...
随机推荐
- Java程序员的现代RPC指南(Windows版预编译好的Protoc支持C++,Java,Python三种最常用的语言,Thrift则支持几乎主流的各种语言)
Java程序员的现代RPC指南 1.前言 1.1 RPC框架简介 最早接触RPC还是初学Java时,直接用Socket API传东西好麻烦.于是发现了JDK直接支持的RMI,然后就用得不亦乐乎,各种大 ...
- MySQL 查询缓存 QUERY_CACHE
查询缓存(QueryCache)保存查询返回的完整结果.当查询命中该缓存,MySQL会立即返回结果,跳过解析.优化和执行阶段. 官方在特定环境测试结果(官方文档中有详细说明): 1.如果对某表进行简单 ...
- Qt在Mac OS X下的编程环境搭建(配置Qt库和编译器,有图,很清楚)
尊重作者,支持原创,如需转载,请附上原地址:http://blog.csdn.net/libaineu2004/article/details/46234079 在Mac OS X下使用Qt开发,需要 ...
- 通过Graphics对象获取它所属的Control
using System.Runtime.InteropServices; [DllImport("user32.dll")] public static extern Int ...
- Linux正则和grep命令
设置命令的默认参数和别名 每次都要输入 ls -l ,烦不烦,我想用 ll 来表示 ls -l, 可以,只要在 ~/.bashrc 中加上 alias ll='ls -l' ,然后运行 source ...
- XP系統IIS最大連接數修改
方法一: 安裝軟件 http://download.microsoft.com/download/iis50/Utility/5.0/NT45/EN-US/MtaEdt22.exe 然後進入 W3S ...
- jQuery框架 的四个入口函数
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- Python socket文件上传下载
python网络编程 程序的目录结构 socketDemo ├── client │ ├── cli.py │ └── local_dir │ └── lianxijiangjie.mp4 ...
- 简单学习js
由于是个前端小白,通过这一两天的学习html,css,js和jquery等,基本上前端会用了,而且熟悉我博客的人来说,没错,我把自己的博客给优化了一下(一些大佬都是禁用模板的所有样式,然后自己设计页面 ...
- selenium3+python3自动化测试学习之网页元素定位
selenium基础实战之定位网页元素技巧 selenium定位网页元素 find_element_by_id,find_element_by_name,find_element_by_class_n ...