We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent bec9217 commit d445621Copy full SHA for d445621
1 file changed
허현빈/10주차/combination sum.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 bkArr = []
8
+ const ans = [];
9
+
10
+ const bk = (nk, sum,start) =>{
11
+ if(sum > target){
12
+ return
13
+ }
14
+ if(sum === target){
15
+ ans.push([...bkArr.slice(0, nk)])
16
17
18
+ for(let i = start; i < candidates.length; i++){
19
+ bkArr[nk] = candidates[i]
20
+ bk(nk+1, sum+candidates[i], i)
21
22
23
+ bk(0, 0, 0)
24
+ return ans
25
+};
0 commit comments