We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e9f8cda commit 63be339Copy full SHA for 63be339
problems/0216.组合总和III.md
@@ -262,7 +262,25 @@ class Solution {
262
```
263
264
Python:
265
-
+```python3
266
+class Solution:
267
+ def combinationSum3(self, k: int, n: int) -> List[List[int]]:
268
+ res = [] #存放结果集
269
+ path = [] #符合条件的结果
270
+ def findallPath(n,k,sum,startIndex):
271
+ if sum > n: return #剪枝操作
272
+ if sum == n and len(path) == k: #如果path.size() == k 但sum != n 直接返回
273
+ return res.append(path[:])
274
+ for i in range(startIndex,9-(k-len(path))+2): #剪枝操作
275
+ path.append(i)
276
+ sum += i
277
+ findallPath(n,k,sum,i+1) #注意i+1调整startIndex
278
+ sum -= i #回溯
279
+ path.pop() #回溯
280
+
281
+ findallPath(n,k,0,1)
282
+ return res
283
+```
284
285
Go:
286
0 commit comments