We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4f00340 commit 3ad73adCopy full SHA for 3ad73ad
combination-sum/casentino.ts
@@ -0,0 +1,20 @@
1
+function combinationSum(candidates: number[], target: number): number[][] {
2
+ const results: number[][] = [];
3
+
4
+ function comb(index: number, arr: number[], sum: number) {
5
+ if (sum === target) {
6
+ results.push([...arr]);
7
+ return;
8
+ }
9
+ if (sum > target || candidates.length <= index) {
10
11
12
+ arr.push(candidates[index]);
13
+ comb(index, arr, sum + candidates[index]);
14
+ arr.pop();
15
+ comb(index + 1, arr, sum);
16
17
18
+ comb(0, [], 0);
19
+ return results;
20
+}
0 commit comments