[置顶] 剑指offer:第25题二叉树和为某一值得路径
2017-06-06 22:34
429 查看
//思路:可以利用全路径逐层递减,在用递归来寻找路径 import java.util.ArrayList; import java.util.List; public class _Test_25_2 { ArrayList<ArrayList<Integer>> arrayListall = new ArrayList<ArrayList<Integer>>(); ArrayList<Integer> arrayList = new ArrayList<Integer>(); private ArrayList<ArrayList<Integer>> findPath(TreeNode root,int target) { if (root == null) { return arrayListall; } arrayList.add(root.val); target -= root.val; if (target == 0 && root.left == null && root.right == null) { arrayListall.add(new ArrayList<Integer>(arrayList)); } if(root.left!=null) findPath(root.left, target); if(root.right!=null) findPath(root.right, target); arrayListall.remove(arrayList.size() - 1); return arrayListall; } }
相关文章推荐
- 剑指offer系列之二十三:二叉树中和为某一值得所有路径
- 剑指Offer——二叉树中和为某一值的路径
- 剑指Offer面试题25(Java版):二叉树中和为某一值的路径
- 剑指offer——二叉树中和为某一值得路径
- 剑指offer --- 二叉树中和为某一数的路径
- 剑指offer系列源码-二叉树中和为某一值的路径
- 《剑指offer》二叉树中和为某一值的路径
- 剑指Offer:二叉树中和为某一值的路径
- 剑指offer 二叉树中和为某一值的路径 java实现
- 《剑指offer》——二叉树中和为某一值的路径
- 剑指offer:二叉树中和为某一值的所有路径(java)
- 剑指offer:输出二叉树和为某一值的所有路径
- 二叉树中和为某一值得路径
- 剑指offer(26):二叉树中和为某一值的路径
- 《剑指offer》二叉树中和为某一值的路径
- 剑指Offer(24)______二叉树中和为某一值的路径
- 二叉树中和为某一值得路径
- 剑指offer:二叉树中和为某一值的路径
- 二叉树中和为某一值得路径
- 二叉树中和为某一值得路径