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 6c7ec07 commit 417109eCopy full SHA for 417109e
1 file changed
combination-sum/nowrobin.js
@@ -0,0 +1,22 @@
1
+/**
2
+ * @param {number[]} candidates
3
+ * @param {number} target
4
+ * @return {number[][]}
5
+ */
6
+function combinationSum(candidates, target) {
7
+ var buffer = [];
8
+ var result = [];
9
+ search(0, target);
10
+ return result;
11
+
12
+ function search(startIdx, target) {
13
+ if (target === 0) return result.push(buffer.slice());
14
+ if (target < 0) return;
15
+ if (startIdx === candidates.length) return;
16
+ buffer.push(candidates[startIdx]);
17
+ search(startIdx, target - candidates[startIdx]);
18
+ buffer.pop();
19
+ search(startIdx + 1, target);
20
+ }
21
+};
22
0 commit comments