Simplest solution in Python By NoOne


#1

class Solution:
# @param A : list of integers
# @param B : integer
# @return a list of list of integers
def combinationSum(self, A, B):
A= set(A)
A= list(A)
res = []
state = []
def recCombinationSum(res,A, state, target, index):

        if index == len(A):
                return
        if target < 0:
            return
        if target == 0:
            res.append(list(state))
        else:
            curr_val = A[index]
            state.append(curr_val)
            recCombinationSum(res,A, state, target-curr_val,index)
            state.pop()
            recCombinationSum(res, A,state, target,index+1)
        
    recCombinationSum(res, A,  state, B, 0)
    #print("res",res)
    res.sort()
    return res