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 f531850 commit 9303e78Copy full SHA for 9303e78
1 file changed
combination-sum/grapefruit13.ts
@@ -0,0 +1,20 @@
1
+function combinationSum(candidates: number[], target: number): number[][] {
2
+ const answer: number[][] = [];
3
+
4
+ function dfs(index: number, path: number[], sum: number) {
5
+ if (sum === target) {
6
+ answer.push([...path]);
7
+ return;
8
+ }
9
+ if (sum > target) return;
10
11
+ for (let i = index; i < candidates.length; i++) {
12
+ path.push(candidates[i]);
13
+ dfs(i, path, sum + candidates[i]);
14
+ path.pop();
15
16
17
18
+ dfs(0, [], 0);
19
+ return answer;
20
+}
0 commit comments