Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 7bcd716

Browse files
Merge pull request youngyangyang04#943 from jxxiao/master
修复 0077.组合 python未剪枝和剪枝代码一样的问题
2 parents d89b396 + 8614090 commit 7bcd716

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

problems/0077.组合.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ class Solution:
405405
if len(path) == k:
406406
res.append(path[:])
407407
return
408-
for i in range(StartIndex, n-(k-len(path)) + 2):
408+
for i in range(StartIndex, n + 1):
409409
path.append(i)
410410
backtrack(n, k, i+1)
411411
path.pop()
@@ -414,7 +414,7 @@ class Solution:
414414
```
415415

416416
剪枝:
417-
```python3
417+
```python
418418
class Solution:
419419
def combine(self, n: int, k: int) -> List[List[int]]:
420420
res=[] #存放符合条件结果的集合
@@ -423,7 +423,7 @@ class Solution:
423423
if len(path) == k:
424424
res.append(path[:])
425425
return
426-
for i in range(startIndex,n-(k-len(path))+2): #优化的地方
426+
for i in range(startIndex,n - (k - len(path)) + 2): #优化的地方
427427
path.append(i) #处理节点
428428
backtrack(n,k,i+1) #递归
429429
path.pop() #回溯,撤销处理的节点

0 commit comments

Comments
 (0)