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 4f956d6 commit e783ad8Copy full SHA for e783ad8
combination-sum/jun0811.js
@@ -0,0 +1,27 @@
1
+/**
2
+ * @param {number[]} candidates
3
+ * @param {number} target
4
+ * @return {number[][]}
5
+ */
6
+var combinationSum = function (candidates, target) {
7
+ const result = [];
8
+ candidates.sort((a, b) => a - b);
9
+ function backTracking(start, arr, total) {
10
+ if (total == target) {
11
+ result.push([...arr]);
12
+ return;
13
+ }
14
+
15
+ for (let i = start; i < candidates.length; i++) {
16
+ const cur = candidates[i];
17
+ if (cur + total > target) {
18
19
20
21
+ backTracking(i, [...arr, cur], total + cur);
22
23
24
25
+ backTracking(0, [], 0);
26
+ return result;
27
+};
0 commit comments