[leetCode刷题笔记]113. Path Sum II
来源:互联网 发布:mastercam攻丝怎么编程 编辑:程序博客网 时间:2024/05/22 04:50
/** * Definition for a binary tree node. * 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>> res = new ArrayList<List<Integer>>(); List<Integer> path = new ArrayList<Integer>(); helper(root, sum, path, res); return res; } private void helper (TreeNode root, int sum, List<Integer> path, List<List<Integer>> res) { if (root == null) { return; } path.add(root.val); if (root.left == null && root.right == null) { if (sum == root.val) { res.add(new ArrayList<Integer>(path)); } path.remove(path.size() - 1); return; } helper(root.left, sum - root.val, path, res); helper(root.right, sum - root.val, path, res); path.remove(path.size() - 1); return; }}
阅读全文
0 0
- [leetCode刷题笔记]113. Path Sum II
- leetcode笔记:Path Sum II
- [leetcode刷题系列]Path Sum II
- LeetCode刷题笔录Path Sum II
- LeetCode 113. Path Sum II
- [LeetCode]113.Path Sum II
- [Leetcode] 113. Path Sum II
- [leetcode] 113.Path Sum II
- [LeetCode]113. Path Sum II
- LeetCode: 113. Path Sum II
- leetcode 113. Path Sum II
- 113. Path Sum II LeetCode
- leetcode 113. Path Sum II
- LeetCode *** 113. Path Sum II
- Leetcode 113. Path Sum II
- LeetCode 113. Path Sum II
- LeetCode 113. Path Sum II
- LeetCode - 113. Path Sum II
- AOP实现Spring多数据源操作
- 我的github&&Git学习资源
- 82-83_游戏项目_使用继承封装MyFrame作为以后窗口类共同父类
- 基础技术篇 7 —— NB-IoT技术(二)
- Android-APP之桌面宠物
- [leetCode刷题笔记]113. Path Sum II
- tomcat在add项目的时候,project facet java version 6.0 is not supported
- R中lines()和abline()函数
- 使用ViewFlipper实现屏幕切换动画效果
- Linux系统编程——特殊进程之僵尸进程
- Java IO 操作基础1---普通文件的相关操作
- git submodule以及被忽略的.gitignore
- Django模型设计详解系列之三
- Spark中RDD转换成DataFrame的两种方式(分别用Java和scala实现)