美文网首页
77. Combinations

77. Combinations

作者: April63 | 来源:发表于2018-06-28 15:22 被阅读0次

写多了果然是比价顺手了。但这题很简单呀

class Solution(object):
    def combine(self, n, k):
        """
        :type n: int
        :type k: int
        :rtype: List[List[int]]
        """
        res = []
        self.dfs(0, n, k, 1, res, [])
        return res
    def dfs(self, count, n, k, start, res, temp):
        if count == k:
            res.append(temp)
            return
        for i in range(start, n+1):
            self.dfs(count+1, n, k, i+1, res, temp+[i])

相关文章

网友评论

      本文标题:77. Combinations

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