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 643b9c7 commit 36f10c9Copy full SHA for 36f10c9
combination-sum/byol-han.js
@@ -0,0 +1,25 @@
1
+/**
2
+ * @param {number[]} candidates
3
+ * @param {number} target
4
+ * @return {number[][]}
5
+ */
6
+var combinationSum = function (candidates, target) {
7
+ const result = [];
8
+
9
+ function backtrack(remaining, combination, start) {
10
+ if (remaining === 0) {
11
+ result.push([...combination]);
12
+ return;
13
+ }
14
+ if (remaining < 0) return;
15
16
+ for (let i = start; i < candidates.length; i++) {
17
+ combination.push(candidates[i]);
18
+ backtrack(remaining - candidates[i], combination, i); // 같은 숫자 다시 사용 가능
19
+ combination.pop(); // backtrack
20
21
22
23
+ backtrack(target, [], 0);
24
+ return result;
25
+};
0 commit comments