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 828972b commit 69fcd06Copy full SHA for 69fcd06
combination-sum/juhui-jeong.ts
@@ -0,0 +1,28 @@
1
+// 시간 복잡도: O(2^(target / minCandidate))
2
+// 공간 복잡도: O(target / minCandidate)
3
+function combinationSum(candidates: number[], target: number): number[][] {
4
+ const result: number[][] = [];
5
+
6
+ const dfs = (index: number, remain: number, path: number[]) => {
7
+ if (remain === 0) {
8
+ result.push([...path]);
9
+ return;
10
+ }
11
12
+ if (remain < 0 || index === candidates.length) {
13
14
15
16
+ const num = candidates[index];
17
18
+ path.push(num);
19
+ dfs(index, remain - num, path);
20
+ path.pop();
21
22
+ dfs(index + 1, remain, path);
23
+ };
24
25
+ dfs(0, target, []);
26
27
+ return result;
28
+}
0 commit comments