mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 00:43:04 +08:00
Merge pull request #943 from jxxiao/master
修复 0077.组合 python未剪枝和剪枝代码一样的问题
This commit is contained in:
@ -405,7 +405,7 @@ class Solution:
|
||||
if len(path) == k:
|
||||
res.append(path[:])
|
||||
return
|
||||
for i in range(StartIndex, n-(k-len(path)) + 2):
|
||||
for i in range(StartIndex, n + 1):
|
||||
path.append(i)
|
||||
backtrack(n, k, i+1)
|
||||
path.pop()
|
||||
@ -414,7 +414,7 @@ class Solution:
|
||||
```
|
||||
|
||||
剪枝:
|
||||
```python3
|
||||
```python
|
||||
class Solution:
|
||||
def combine(self, n: int, k: int) -> List[List[int]]:
|
||||
res=[] #存放符合条件结果的集合
|
||||
@ -423,7 +423,7 @@ class Solution:
|
||||
if len(path) == k:
|
||||
res.append(path[:])
|
||||
return
|
||||
for i in range(startIndex,n-(k-len(path))+2): #优化的地方
|
||||
for i in range(startIndex,n - (k - len(path)) + 2): #优化的地方
|
||||
path.append(i) #处理节点
|
||||
backtrack(n,k,i+1) #递归
|
||||
path.pop() #回溯,撤销处理的节点
|
||||
|
Reference in New Issue
Block a user