原题链接

子母题 112 Path Sum

跟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)的更多相关文章

  1. [LeetCode] 113. Path Sum II ☆☆☆(二叉树所有路径和等于给定的数)

    LeetCode 二叉树路径问题 Path SUM(①②③)总结 Path Sum II leetcode java 描述 Given a binary tree and a sum, find al ...

  2. [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 ...

  3. [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 ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. [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 ...

  9. 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 ...

随机推荐

  1. XP下安装ubuntu

    一,环境说明 dell vostro 1400笔记本,winxp sp3操作系统,ubuntu-9.10-desktop-i386.iso 写这篇随笔的时候我用的已经是ubuntu了. 我是在我的移动 ...

  2. 修改zookeeper jvm参数

    在zkServer.sh中,增加以下参数: start)    echo  -n "Starting zookeeper ... "    if [ -f $ZOOPIDFILE ...

  3. Arcgis Server 10.4.1 搭建集群环境

    1.准备工作 Arcgis Server 10.4.1  以及许可一枚 共享存储(通过UNC路径访问,如"\\server1\arcgisserver\") 服务器两台(虚拟机也可 ...

  4. Metasploit学习笔记

    原创博客,转载请注出处! 各位看官可参看——Metasploit实验操作 1.打开msf        msfconsole2.帮助选项:    msfconsole -h        显示在msf ...

  5. form表单提交不刷新页面的方法

    方法1:给form表单加onsubmit事件,值为return false; <form action="" method="post"  onsubmi ...

  6. 【oracle】Oracle整理笔记

    原博主总结了很多技能和小技巧,本人觉的非常实用,转载记录下: Oracle学习笔记整理手册 作者:@smileNicky 链接:https://blog.csdn.net/u014427391/art ...

  7. 经典Java笔试面试题

    面向对象编程(OOP) Java是一个支持并发.基于类和面向对象的计算机编程语言.下面列出了面向对象软件开发的优点: 代码开发模块化,更易维护和修改. 代码复用. 增强代码的可靠性和灵活性. 增加代码 ...

  8. TCP/IP 第一章

    1,tcp/ip协议族作用:连接互联网中的计算机,并使其通信.可以想象互联网的计算机有不同的操作系统,如linux.unix.bsd.srv.windows.mac等.这么多操作系统对tcp/ip的实 ...

  9. asp.net core 系列之Dependency injection(依赖注入)

    这篇文章主要讲解asp.net core 依赖注入的一些内容. ASP.NET Core支持依赖注入.这是一种在类和其依赖之间实现控制反转的一种技术(IOC). 一.依赖注入概述 1.原始的代码 依赖 ...

  10. 如何配置selinux

    参考命令:   一.开启/关闭selinux   getenforce:查看selinux运行状态 setenforce 0 :关闭selinux setenforce 1 :开启selinux 系统 ...