Easier than editorial


#1

Comment body goes here.
void solve(int i,vector &A,int sum,vector temp,set<vector> &ans)
{
if(sum<0)
return ;
if(sum==0)
{
// sort(temp.begin(),temp.end());
ans.insert(temp);
return ;
}
if(i>=A.size())
return ;
solve(i+1,A,sum,temp,ans);
temp.push_back(A[i]);
solve(i+1,A,sum-A[i],temp,ans);
temp.pop_back();
}
vector<vector > Solution::combinationSum(vector &A, int B) {
set<vector> ans;
vector temp;
int i=0;
sort(A.begin(),A.end());
solve(i,A,B,temp,ans);
vector<vector> res;
for(auto x: ans)
{
res.push_back(x);
}
return res;

}