class Solution:
def __init__(self):
self.result = []
def backtracing(self,n,k,startindex,result_tmp):
if len(result_tmp)==k:
self.result.append(result_tmp[:])
return
for i in range(startindex,n+1):
result_tmp.append(i)
self.backtracing(n,k,i+1,result_tmp)
result_tmp.pop()
def combine(self, n: int, k: int) -> List[List[int]]:
result_tmp=[]
self.backtracing(n,k,1,result_tmp)
return self.result
代码随想录算法day22| 回溯算法part1||
最新推荐文章于 2024-09-04 21:39:45 发布