1 Star 0 Fork 1

dllearn/geektime-algorithm-learn

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
f.go 453 Bytes
一键复制 编辑 原始数据 按行查看 历史
dryyun 提交于 3年前 . 0077
package combinations
// 77. 组合
// https://leetcode-cn.com/problems/combinations/
var res [][]int
func combine(n int, k int) [][]int {
res = make([][]int, 0)
tmp := []int{}
dfs(n, k, 1, tmp)
return res
}
func dfs(n, k, i int, tmp []int) {
if len(tmp) == k {
res = append(res, append([]int{}, tmp...))
return
}
for s := i; s <= n-(k-len(tmp))+1; s++ {
tmp = append(tmp, s)
dfs(n, k, s+1, tmp)
tmp = tmp[:len(tmp)-1]
}
return
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/dllearn/geektime-algorithm-learn.git
git@gitee.com:dllearn/geektime-algorithm-learn.git
dllearn
geektime-algorithm-learn
geektime-algorithm-learn
55fa3f222b36

搜索帮助