My simple recursive C++ solution


#1

void helper(vectorA,vector<vector>&ans,int index,vectorsub)
{
if(sub.size()==A.size())
{
ans.push_back(sub);
return;
}
for(int i=index;i<A.size();i++)
{
int t = A[index];
A[index] = A[i];
A[i] = t;
sub.push_back(A[index]);
helper(A,ans,index+1,sub);
sub.pop_back();
}
}

vector<vector> Solution::permute(vector &A) {
vector<vector>ans;
vectorsub;
helper(A,ans,0,sub);
return ans;
}
//