MCPcopy Create free account
hub / github.com/Hsinha11/Leetcode-solutions / backtrack

Method backtrack

39-combination-sum/combination-sum.java:12–24  ·  view source on GitHub ↗
(List<List<Integer>> result, List<Integer> temp, int[] candidates, int remain, int start)

Source from the content-addressed store, hash-verified

10 }
11
12 private void backtrack(List<List<Integer>> result, List<Integer> temp, int[] candidates, int remain, int start) {
13 if (remain < 0) return;
14 if (remain == 0) {
15 result.add(new ArrayList<>(temp));
16 return;
17 }
18
19 for (int i = start; i < candidates.length; i++) {
20 temp.add(candidates[i]);
21 backtrack(result, temp, candidates, remain - candidates[i], i);
22 temp.remove(temp.size() - 1);
23 }
24 }
25}

Callers 1

combinationSumMethod · 0.95

Calls 1

removeMethod · 0.80

Tested by

no test coverage detected