class Solution:
def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]:
ans = []
def backtrack(curr, remaining, start):
if remaining == 0:
ans.append(list(curr))
return
if remaining < 0:
return
for i in range(start, len(candidates)):
candidate = candidates[i]
curr.append(candidate)
backtrack(curr, remaining - candidate, i)
curr.pop()
backtrack([], target, 0)
return ans