Simple 15 line easy solution


#1

void per(vector&A,int l,int r,vector<vector>&v){
if(l==r)v.push_back(A);
else{
for(int i=l;i<=r;i++){
swap(A[i],A[l]);
per(A,l+1,r,v);
swap(A[i],A[l]);
} } }

vector<vector > Solution::permute(vector &A) {
vector<vector>v;
int n=A.size();
per(A,0,n-1,v);
return v; }