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 0cd8146 commit c787f33Copy full SHA for c787f33
combination-sum/gwbaik9717.js
@@ -0,0 +1,32 @@
1
+/**
2
+ * @param {number[]} candidates
3
+ * @param {number} target
4
+ * @return {number[][]}
5
+ */
6
+var combinationSum = function (candidates, target) {
7
+ const answer = [];
8
+ const n = candidates.length;
9
+ const combi = (i, sum, arr) => {
10
+ for (let j = i; j < n; j++) {
11
+ const candidate = candidates[j];
12
+ const newSum = sum + candidate;
13
+
14
+ if (newSum === target) {
15
+ answer.push([...arr, candidate]);
16
+ continue;
17
+ }
18
19
+ if (newSum > target) {
20
21
22
23
+ if (newSum < target) {
24
+ combi(j, newSum, [...arr, candidate]);
25
26
27
+ };
28
29
+ combi(0, 0, []);
30
31
+ return answer;
32
+};
0 commit comments