1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| public class Solution { public class TreeNode { int val = 0; TreeNode left = null; TreeNode right = null; public TreeNode(int val) { this.val = val;
} } private ArrayList<ArrayList<Integer>> listAll = new ArrayList<>(); private ArrayList<Integer> list = new ArrayList<>(); public ArrayList<ArrayList<Integer>> FindPath(TreeNode root,int target) { if(root == null){ return listAll; } list.add(root.val); target -= root.val; if(target == 0 && root.left == null && root.right == null){ listAll.add(new ArrayList<Integer>(list)); } FindPath(root.left,target); FindPath(root.right,target); list.remove(list.size()-1); return listAll; } }
|