My C++ code, tell me how to improve


#1

void findCombinationSum(vector input,vector<vector> &res,vector &subset,int sum,int index)
{
if(sum == 0)
{
res.push_back(subset);
return;
}
if(sum < 0)
{
return;
}

for(int i=index;i<input.size();i++)
{
subset.push_back(input[i]);

   findCombinationSum(input,res,subset,sum - subset.back(),i);
   
   subset.pop_back();

}
}

vector<vector > Solution::combinationSum(vector &A, int B)
{
vector<vector> res;
vector subset;

sort(A.begin(),A.end());//most useless step needed to pass IB test cases

findCombinationSum(A,res,subset,B,0);//0 for index

set<vector> s(res.begin(),res.end());
res.assign(s.begin(),s.end());

return res;

}