MCPcopy
hub / github.com/qiyuangong/leetcode / backtracking

Method backtracking

java/039_Combination_Sum.java:14–27  ·  view source on GitHub ↗
(int[] candidates, int index, int tsize, int target, List<Integer> temp)

Source from the content-addressed store, hash-verified

12 return answer;
13 }
14 private void backtracking(int[] candidates, int index, int tsize, int target, List<Integer> temp) {
15 if (target == 0) {
16 answer.add(new ArrayList(temp));
17 return;
18 }
19
20 for (int i = index, len = candidates.length; i < len; i++) {
21 if (candidates[i] <= target) {
22 temp.add(candidates[i]);
23 backtracking(candidates, i, (tsize + 1), (target - candidates[i]), temp);
24 temp.remove(tsize);
25 }
26 }
27 }
28}
29

Callers 1

combinationSumMethod · 0.95

Calls 2

addMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected