113. Path Sum II
来源:互联网 发布:余世存 知乎 编辑:程序博客网 时间:2024/05/22 18:55
Path Sum II
代码
public class Solution { List<List<Integer>> res = new ArrayList<List<Integer>>(); public List<List<Integer>> pathSum(TreeNode root, int sum) { if(root == null){ return res; } Stack<Integer> path = new Stack<Integer>(); helper(root, sum, path); return res; } public void helper(TreeNode root, int sum, Stack<Integer> path){ path.push(root.val); if(root.left == null && root.right == null){ if(root.val == sum) res.add(new ArrayList<Integer>(path)); } if(root.left != null){ helper(root.left, sum-root.val, path); } if(root.right != null){ helper(root.right, sum-root.val, path); } path.pop(); }}
0 0
- 113. Path Sum II
- 113. Path Sum II
- 113. Path Sum II
- 113. Path Sum II
- 113. Path Sum II
- 113. Path Sum II
- 113. Path Sum II
- 113. Path Sum II
- 113. Path Sum II
- 113. Path Sum II
- 113. Path Sum II
- 113. Path Sum II
- 113. Path Sum II
- 113. Path Sum II
- 113. Path Sum II
- 113. Path Sum II
- 113. Path Sum II
- 113. Path Sum II
- 【iOS 开发】从 setNeedsLayout 说起
- hdu 1033 Edge
- boost创建线程例子
- web.xml 配置随笔
- SQL-----group by 查询多个字段
- 113. Path Sum II
- Hibernate -- 普通sql返回结果字段名称改为小写
- iOS开发系统相册的选取
- 6walker侧滑
- 欢迎使用CSDN-markdown编辑器
- hadoop webhdfs 服务开启及使用
- 为RecyclerView打造通用Adapter 让RecyclerView更加好用
- 安卓开发入门——环境的搭建
- 不小心删掉oracle数据库datafiles的dbf文件的解决办法