[tag] DFS, combination
class Solution:
def combine(self, n: int, k: int) -> List[List[int]]:
nums = [i for i in range(1, n+1)]
temp = []
ans = []
def dfs(index):
if len(temp) == k:
ans.append(temp.copy())
return
for i in range(index, len(nums)):
temp.append(nums[i])
dfs(i+1)
temp.pop()
dfs(0)
return ans