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 8132541 commit 578a50cCopy full SHA for 578a50c
combination-sum/iam-edwin.py
@@ -0,0 +1,20 @@
1
+from typing import List
2
+
3
4
+class Solution:
5
+ def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]:
6
+ result = [[[] for _ in range(target + 1)] for _ in range(len(candidates))]
7
8
+ for index in range(len(candidates)):
9
+ num = candidates[index]
10
+ for subTarget in range(1, target + 1):
11
+ maxUseCount = subTarget // num
12
+ for useCount in range(0, maxUseCount + 1):
13
+ subSubTarget = subTarget - num * useCount
14
+ if subSubTarget == 0:
15
+ result[index][subTarget].append([num] * useCount)
16
+ else:
17
+ for item in result[index - 1][subSubTarget]:
18
+ result[index][subTarget].append(item + [num] * useCount)
19
20
+ return result[len(candidates) - 1][target]
0 commit comments