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 82e6ecb commit 191748fCopy full SHA for 191748f
1 file changed
combination-sum/reeseo3o.js
@@ -0,0 +1,20 @@
1
+const combinationSum = (candidates, target) => {
2
+ const result = [];
3
+
4
+ const backtrack = (startIndex, current, remaining) => {
5
+ if (remaining === 0) {
6
+ result.push([...current]);
7
+ return;
8
+ }
9
+ if (remaining < 0) return;
10
11
+ for (let i = startIndex; i < candidates.length; i++) {
12
+ current.push(candidates[i]);
13
+ backtrack(i, current, remaining - candidates[i]);
14
+ current.pop();
15
16
+ };
17
18
+ backtrack(0, [], target);
19
+ return result;
20
+};
0 commit comments