C++ solution simple af


#1

vector<vector> ans;
void func(vector &a,int n,int i,vector temp){
if (i==n){
ans.push_back(temp);
return;
}
for(int j=0;j<n;j++){
if(temp[j]==-1){
temp[j] = a[i];
func(a,n,i+1,temp);
temp[j] = -1;
}
}

}
vector<vector > Solution::permute(vector &A) {
ans.resize(0);
int n = A.size();
vectortemp(n);
for(int i=0;i<n;i++){
temp[i]=-1;
}
func(A,n,0,temp);
return ans;
}