Different approach C++ solution


#1
void subset(vector<int> &A,vector<bool> &visit,vector<int> sub, vector<vector<int>> &ans)
{
    if(sub.size()==A.size())
    {
        ans.push_back(sub);
        return;
    }
    for(int i=0;i<A.size();i++)
    {
        if(visit[i]==false)
        {
            visit[i]=true;
            sub.push_back(A[i]);
            subset(A,visit,sub,ans);
            visit[i]=false;
            sub.pop_back();
        }
    }
    
}

vector<vector<int> > Solution::permute(vector<int> &A) {
    vector<bool> visit(A.size(),false);
    vector<vector<int>> ans;
    vector<int> sub;
    subset(A,visit,sub,ans);
    return ans;
}