(
int[] candidates,
int target,
List<List<Integer>> ans,
List<Integer> cur,
int index
)
| 8 | } |
| 9 | |
| 10 | public void backtrack( |
| 11 | int[] candidates, |
| 12 | int target, |
| 13 | List<List<Integer>> ans, |
| 14 | List<Integer> cur, |
| 15 | int index |
| 16 | ) { |
| 17 | if (target == 0) { |
| 18 | ans.add(new ArrayList(cur)); |
| 19 | } else if (target < 0 || index >= candidates.length) { |
| 20 | return; |
| 21 | } else { |
| 22 | cur.add(candidates[index]); |
| 23 | backtrack(candidates, target - candidates[index], ans, cur, index); |
| 24 | |
| 25 | cur.remove(cur.get(cur.size() - 1)); |
| 26 | backtrack(candidates, target, ans, cur, index + 1); |
| 27 | } |
| 28 | } |
| 29 | } |
no test coverage detected