What's wrong with my c++ recursive solution


#1

vector<vector> ans;

void sub(vector &op, vector &ip)
{
if(ip.size()==0)
{
ans.push_back(op);
return;
}
vector op1=op;
vector op2=op;
op1.push_back(ip[0]);
ip.erase(ip.begin()+0);
sub(op1,ip);
sub(op2,ip);
return;
}

vector<vector> Solution::subsets(vector &A) {
sort(A.begin(),A.end());
vector v;
sub(v,A);
return ans;
}


#2
  1. you dont need to pass the input and output variables by reference.
  2. Don’t forget to clear the global variable, you can store it in some other variable and return that.
  3. Also, sort the vector when you are pushing it into the global variable.