Open
Description
I came across a Python solution for the Combination Sum problem that was missing. The code below works for that purpose.
res, sol = [], []
def backtrack():
if sum(sol) == target:
res.append(sol[:])
return
if sum(sol) > target:
return
for i in candidates:
if len(sol) > 0 and i < sol[-1]:
continue
sol.append(i)
backtrack()
sol.pop()
backtrack()
return res
Metadata
Metadata
Assignees
Labels
No labels