leetcode/39-240619-pass/main.py

17 lines
526 B
Python
Raw Normal View History

2024-06-19 23:59:30 +02:00
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))