Combination Sum LeetCode solution in JavaScript

1
function recursion(index, list, target, res, arr) {
2
if (index == arr.length) {
3
if (target == 0) {
4
res.push([...list]);
5
}
6
return;
7
}
8

9
if (arr[index] <= target) {
10
list.push(arr[index]);
11

12
recursion(index, list, target - arr[index], res, arr);
13

14
list.pop();
15
}
16

17
recursion(index + 1, list, target, res, arr);
18
}
19
var combinationSum = function (candidates, target) {
20
let res = [];
21
recursion(0, [], target, res, candidates);
22
return res;
23
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0