修复 0077.组合 python未剪枝和剪枝代码一样的问题

This commit is contained in:
jxxiao
2021-12-10 21:46:15 +08:00
parent 94e5dea6f0
commit 8614090773

View File

@ -405,7 +405,7 @@ class Solution:
if len(path) == k: if len(path) == k:
res.append(path[:]) res.append(path[:])
return return
for i in range(StartIndex, n-(k-len(path)) + 2): for i in range(StartIndex, n + 1):
path.append(i) path.append(i)
backtrack(n, k, i+1) backtrack(n, k, i+1)
path.pop() path.pop()
@ -414,7 +414,7 @@ class Solution:
``` ```
剪枝 剪枝
```python3 ```python
class Solution: class Solution:
def combine(self, n: int, k: int) -> List[List[int]]: def combine(self, n: int, k: int) -> List[List[int]]:
res=[] #存放符合条件结果的集合 res=[] #存放符合条件结果的集合