Path Sum II
来源:互联网 发布:孕妇必知的民间禁忌 编辑:程序博客网 时间:2024/06/15 11:54
/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */public class Solution { public List<List<Integer>> pathSum(TreeNode root, int sum) { List<List<Integer>> result = new ArrayList<List<Integer>>(); if (root != null){ pathSumHelper(root, sum, result, new ArrayList<Integer>()); } return result; } public void pathSumHelper(TreeNode root, int sum, List<List<Integer>> result, List<Integer> path){ if (root == null) return; path.add(root.val); if (root.val == sum && root.left == null && root.right == null){ result.add(path); }else{ pathSumHelper(root.left, sum-root.val, result, new ArrayList<Integer>(path)); pathSumHelper(root.right, sum-root.val, result, new ArrayList<Integer>(path)); } }}
0 0
- LeetCode: Path Sum II
- LeetCode Path Sum II
- [Leetcode] Path Sum II
- LeetCode: Path Sum II
- Path Sum II
- [LeetCode] Path Sum II
- 【leetcode】Path Sum II
- [113]Path Sum II
- Path Sum II
- Path Sum II
- [LeetCode]Path Sum II
- Path Sum II
- Path Sum II
- [Leetcode]Path Sum II
- [leetcode]Path Sum II
- Path Sum II
- Leetcode: Path Sum II
- Path Sum II
- 使用ServletFileUpload实现上传
- Manifest.permission_group权限组
- 织梦仿站系列教程第十讲——通用头部(六)搜索框
- “未能加载文件或程序集“AspNetPager”或它的某一个依赖项。系统找不到指定的路径。”的解决方法
- Eclipse get/set方法自动加上字段注释
- Path Sum II
- ANDROID自定义输入法-自定义键盘
- href&src相对路径表示
- 飘逸的python - 一个极简的event系统
- JS--数组
- 《C程序设计语言》第一章作业答案
- tomcat5项目转移到安装版tomcat6的问题
- Javascript异步编程的4种方法
- mysql的“Got error 28 from storage engine”错误