77. Combinations (Medium) - TengnanYao/daily_leetcode GitHub Wiki

class Solution:
    def combine(self, n: int, k: int) -> List[List[int]]:
        result = []
        def dfs(i, cur):
            if len(cur) == k:
                result.append(cur)
            elif i < n + 1:
                dfs(i + 1, cur + [i])
                dfs(i + 1, cur)
        dfs(1, [])
        return result