Problem :

https://leetcode.com/problems/combination-sum/


My Solution :

class Solution:
def combinationSum(self, candidates, target):
def dfs(path, remain, i):
if remain == 0:
ans.append(path[:])
return
if i < len(candidates) and candidates[i] <= remain:
dfs(path + [candidates[i]], remain-candidates[i], i)
dfs(path, remain, i+1)

candidates.sort()
ans = []
dfs([], target, 0)
return ans