From 8614090773bf77964b350a31afac82752fd59234 Mon Sep 17 00:00:00 2001 From: jxxiao Date: Fri, 10 Dec 2021 21:46:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=200077.=E7=BB=84=E5=90=88=20?= =?UTF-8?q?python=E6=9C=AA=E5=89=AA=E6=9E=9D=E5=92=8C=E5=89=AA=E6=9E=9D?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=B8=80=E6=A0=B7=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0077.组合.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/problems/0077.组合.md b/problems/0077.组合.md index 16313cb8..edd9f393 100644 --- a/problems/0077.组合.md +++ b/problems/0077.组合.md @@ -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() #回溯,撤销处理的节点