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 7773d46 commit 2ed50adCopy full SHA for 2ed50ad
combination-sum/1lsang.ts
@@ -0,0 +1,16 @@
1
+function combinationSum(candidates: number[], target: number): number[][] {
2
+ // arr: index까지 갈 수 있는 combinationSum
3
+ const arr:number[][][] = Array.from({ length: target + 1 }, () => [] as number[][]);
4
+ // 0을 만들 수 있는 방법은 숫자가 없는 것
5
+ arr[0].push([] as number[]);
6
+
7
+ for (const candidate of candidates) {
8
+ for (let n = candidate; n <= target; n++) {
9
+ for (const combination of arr[n-candidate]) {
10
+ arr[n].push([...combination, candidate]);
11
+ }
12
13
14
+ console.log(arr);
15
+ return arr[target];
16
+};
0 commit comments