标签:
这道题纯dfs, 但是在 Line 13处做了个剪枝 从84ms 提高到68 ms
1 class Solution: 2 def __init__(self): 3 self.ans = [] 4 5 def combine(self, n, k): 6 self.help(n, k, 0, []) 7 return self.ans 8 9 def help(self, n, k, l, cur): 10 if k == 0: 11 self.ans.append(cur[:]) 12 return 13 if n - l < k: 14 return 15 for i in range(l, n): 16 self.help(n,k-1,i+1,cur+[i+1])
标签:
原文地址:http://www.cnblogs.com/dapanshe/p/4665997.html