美文网首页leetcode
77. Combinations.go

77. Combinations.go

作者: AnakinSun | 来源:发表于2019-03-23 13:32 被阅读0次

回溯算法

func combine(n int, k int) [][]int {
    var res [][]int
    helper(&res, []int{}, 1, n, k)
    return res
}

func helper(res *[][]int, coms []int, start int, n int, k int) {
    if k == 0 {
        tmp := []int{}
        tmp = append(tmp, coms...)
        *res = append(*res, tmp)
        return
    }
    for i := start; i <= n; i++ {
        coms = append(coms, i)
        helper(res, coms, i+1, n, k-1)
        coms = coms[:len(coms)-1]
    }
}

相关文章

  • 77. Combinations.go

    回溯算法

  • 77. Combinations

    77. Combinations

  • LeetCode #77 #39 #40 #216 #377 #

    77. Combinations https://leetcode.com/problems/combinatio...

  • Longest Common Subsequence

    LintCode 77. Longest Common Subsequence Algorithm Two inp...

  • 77.

    知道信息的作用是减少不确定性,这对我们又有什么作用呢?对我们在大数据中分析海量数据有什么作用? 大数据包含海量的信...

  • 77.

    今晚流氓兔推荐的歌曲是《浪费》,徐佳莹。今天下午走在广州东站的某个出口处,听到商店里传出这首歌,很大声,男女合唱的...

  • 77.

    北京的夏日,阳光充足。杨三把手搁庄煜脑袋上,两人找了个地方乘凉。 田恩走了过来,微笑着朝两人打招呼。 “煜儿,你们...

  • 77. 可怜的成功尺度(张鸣)单行本《游戏玩家》

    77. 可怜的成功尺度(张鸣)单行本《游戏玩家》

  • 77

    77. 4TB FREE SPACE 28.4G ----------- BluRay ----------- N...

  • [DFS]77. Combinations

    分类:DFS 时间复杂度: O(nk)* 77. Combinations Given two integers ...

网友评论

    本文标题:77. Combinations.go

    本文链接:https://www.haomeiwen.com/subject/qlcsvqtx.html