Using set handling duplicate


#1

void fun(set<vector>&ans,vectorcurr,vectorarr,int s,int sum)
{

    if(sum==0)
{    sort(curr.begin(),curr.end());
     ans.insert(curr);
    return;
}   

if(s<=0||sum<=0)return;

curr.push_back(arr[s-1]);
fun(ans,curr,arr,s-1,sum-arr[s-1]);
curr.pop_back();

fun(ans,curr,arr,s-1,sum);

curr.push_back(arr[s-1]);
fun(ans,curr,arr,s,sum-arr[s-1]);
curr.pop_back();

}

vector<vector > Solution::combinationSum(vector &arr, int B) {
sort(arr.begin(),arr.end());
int n=arr.size();
set<vector>ans;
vectorcurr;
fun(ans,curr,arr,n,B);
vector<vector>anss;
for(auto i:ans)
anss.push_back(i);
return anss;

}