Skip to content

Commit

Permalink
Merge pull request youngyangyang04#943 from jxxiao/master
Browse files Browse the repository at this point in the history
修复 0077.组合 python未剪枝和剪枝代码一样的问题
  • Loading branch information
youngyangyang04 authored Dec 19, 2021
2 parents d89b396 + 8614090 commit 7bcd716
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions problems/0077.组合.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -414,7 +414,7 @@ class Solution:
```

剪枝:
```python3
```python
class Solution:
def combine(self, n: int, k: int) -> List[List[int]]:
res=[] #存放符合条件结果的集合
Expand All @@ -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() #回溯,撤销处理的节点
Expand Down

0 comments on commit 7bcd716

Please sign in to comment.