77. Combinations
class Solution:
def __init__(self):
self.res = []
def trackback(self, track, index, n, k):
if len(track) == k:
self.res.append(track[:])
return
for i in range(index+1, n+1): #选择列表
if i in track:
continue
track.append(i) #选择
self.trackback(track, i, n, k)
track.pop() # 撤销选择
def combine(self, n: int, k: int) -> List[List[int]]:
track = [] #路径
self.trackback(track, 0, n, k)
return self.res