77. Combinations

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

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)