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 184be39 commit af374c9Copy full SHA for af374c9
โcombination-sum/seungseung88.js
@@ -0,0 +1,27 @@
1
+/**
2
+ * ์๊ฐ๋ณต์ก๋: O(2^n)
3
+ * ๊ณต๊ฐ๋ณต์ก๋: O(target)
4
+ */
5
+
6
+function combinationSum(canditates, target) {
7
+ const result = [];
8
+ const nums = [];
9
10
+ function dfs(start, total) {
11
+ if (total > target) return;
12
+ if (total === target) result.push([...nums]);
13
14
+ // ์ค๋ณต์ ๊ฑฐ๋ฅผ ์ํด start๋ก ์์
15
+ for (let i = start; i < canditates.length; i += 1) {
16
+ num = canditates[i];
17
+ nums.push(num);
18
+ dfs(i, total + num);
19
+ nums.pop();
20
+ }
21
22
23
+ // ์์ ์ธ๋ฑ์ค, ๋์ ํฉ
24
+ dfs(0, 0);
25
26
+ return result;
27
+}
0 commit comments