17 lines
526 B
Python
17 lines
526 B
Python
|
class Solution:
|
||
|
def combinationSum(self, candidates: list[int], target: int) -> list[list[int]]:
|
||
|
candidates.sort()
|
||
|
rlt = []
|
||
|
def dfs(cur, l, cur_num):
|
||
|
if cur == 0:
|
||
|
rlt.append(l)
|
||
|
for candidate in candidates:
|
||
|
if cur - candidate >= 0 and candidate >= cur_num:
|
||
|
dfs(cur - candidate, l + [candidate], candidate)
|
||
|
dfs(target, [], candidates[0])
|
||
|
return rlt
|
||
|
|
||
|
|
||
|
sol = Solution()
|
||
|
print(sol.combinationSum([2,3,6,7], 7))
|