MCPcopy Index your code
hub / github.com/neetcode-gh/leetcode / combinationSum

Function combinationSum

javascript/0039-combination-sum.js:8–26  ·  view source on GitHub ↗
(
    candidates,
    target,
    index = 0,
    combination = [],
    combinations = [],
)

Source from the content-addressed store, hash-verified

6 * @return {number[][]}
7 */
8var combinationSum = function (
9 candidates,
10 target,
11 index = 0,
12 combination = [],
13 combinations = [],
14) {
15 const isBaseCase = target < 0;
16 if (isBaseCase) return combinations;
17
18 const isTarget = target === 0;
19 if (isTarget) return combinations.push(combination.slice());
20
21 for (let i = index; i < candidates.length; i++) {
22 backTrack(candidates, target, i, combination, combinations);
23 }
24
25 return combinations;
26};
27
28const backTrack = (candidates, target, i, combination, combinations) => {
29 combination.push(candidates[i]);

Callers 1

backTrackFunction · 0.70

Calls 2

backTrackFunction · 0.70
pushMethod · 0.45

Tested by

no test coverage detected