MCPcopy Create free account
hub / github.com/neetcode-gh/leetcode / comb

Method comb

java/0040-combination-sum-ii.java:11–28  ·  view source on GitHub ↗
(
        int[] candidates,
        int target,
        List<List<Integer>> ans,
        List<Integer> ls,
        int index
    )

Source from the content-addressed store, hash-verified

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

Callers 1

combinationSum2Method · 0.95

Calls 4

addMethod · 0.45
removeMethod · 0.45
getMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected