Skip to content

Commit

Permalink
refactor: 0077.组合.md
Browse files Browse the repository at this point in the history
  • Loading branch information
qiufeihong2018 committed May 1, 2024
1 parent 2d37cd3 commit 3e5c170
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions problems/0077.组合.md
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,32 @@ func dfs(n int, k int, start int) {
```

### Javascript
未剪枝:

```js
var combine = function (n, k) {
// 回溯法
let result = [],
path = [];
let backtracking = (_n, _k, startIndex) => {
// 终止条件
if (path.length === _k) {
result.push(path.slice());
return;
}
// 循环本层集合元素
for (let i = startIndex; i <= _n; i++) {
path.push(i);
// 递归
backtracking(_n, _k, i + 1);
// 回溯操作
path.pop();
}
};
backtracking(n, k, 1);
return result;
};
```

剪枝:

Expand Down

0 comments on commit 3e5c170

Please sign in to comment.