given a set of candidate numbers c without duplicates and a target number t find all unique combinations in c where the candidate numbers sums to t the same repeated number may be chosen from c unlimited number of times note all numbers including target will be positive integers the solution set must not contain duplicate combinations for example given candidate set 2 3 6 7 and target 7 a solution set is 7 2 2 3 backtracking
def combination_sum(candidates, target):

    def dfs(nums, target, index, path, res):
        if target < 0:
            return  
        if target == 0:
            res.append(path)
            return
        for i in range(index, len(nums)):
            dfs(nums, target-nums[i], i, path+[nums[i]], res)

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