题目:
题解:
class Solution:def combine(self, n: int, k: int) -> List[List[int]]:ans = []path = []def dfs(x):remain = k - len(path)if not remain:ans.append(list(path))returnif n + 1 - x > remain:dfs(x + 1)path.append(x)dfs(x + 1)path.pop()dfs(1)return ans