Skip to content

Commit 0ebd5f1

Browse files
committed
添加77. 组合优化JavaScript版本
1 parent 970efed commit 0ebd5f1

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

problems/0077.组合优化.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public:
147147

148148

149149
Java:
150-
```
150+
```java
151151
class Solution {
152152
List<List<Integer>> result = new ArrayList<>();
153153
LinkedList<Integer> path = new LinkedList<>();
@@ -220,6 +220,28 @@ func backtrack(n,k,start int,track []int){
220220
}
221221
```
222222

223+
javaScript:
224+
225+
```js
226+
var combine = function(n, k) {
227+
const res = [], path = [];
228+
backtracking(n, k, 1);
229+
return res;
230+
function backtracking (n, k, i){
231+
const len = path.length;
232+
if(len === k) {
233+
res.push(Array.from(path));
234+
return;
235+
}
236+
for(let a = i; a <= n + len - k + 1; a++) {
237+
path.push(a);
238+
backtracking(n, k, a + 1);
239+
path.pop();
240+
}
241+
}
242+
};
243+
```
244+
223245

224246

225247

0 commit comments

Comments
 (0)