ArrayList<ArrayList<Integer>> arrayList = new ArrayList<>(); ArrayList<Integer> list = new ArrayList<>(); public ArrayList<ArrayList<Integer>> FindPath(TreeNode root,int target) { if(root == null) return arrayList; list.add(root.val); target -= root.val; if(target==0&&root.left == null && root.right==null){ arrayList.add(new ArrayList<Integer>(list)); } FindPath(root.left,target); FindPath(root.right,target); list.remove(list.size()-1); return arrayList; }