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 b64ded9 commit 4951f54Copy full SHA for 4951f54
โcombination-sum/yoouyeon.tsโ
@@ -0,0 +1,25 @@
1
+// [39] Combination Sum
2
+
3
+function combinationSum(candidates: number[], target: number): number[][] {
4
+ const n = candidates.length;
5
+ const output: number[][] = [];
6
7
+ function dfs(arr: number[], startIdx: number, sum: number) {
8
+ if (sum === target) {
9
+ output.push([...arr]);
10
+ return;
11
+ }
12
+ if (sum > target) return;
13
14
+ // ํ์ฌ ์ซ์๋ถํฐ ๋ค์ ์์ (์ค๋ณต ์ ํ์ด ๊ฐ๋ฅํ๊ธฐ ๋๋ฌธ)
15
+ for (let idx = startIdx; idx < n; idx++) {
16
+ arr.push(candidates[idx]);
17
+ dfs(arr, idx, sum + candidates[idx]);
18
+ arr.pop();
19
20
21
22
+ dfs([], 0, 0);
23
24
+ return output;
25
+}
0 commit comments