How can i optimize my sol and reduce time complexity


#1
bool iscorrect(vector<int>&temp,int x)
{
    if(temp.size()==0) return true;
    else
    {
        for(int i=0;i<temp.size();i++)
        {
            if(x==temp[i]) return false;
        }
        return true;
    }
}
void func(vector<int>&A, vector<vector<int>>&ans, vector<int>&temp,int index)
{
    if(index==A.size())
    {
        ans.push_back(temp);
    }
    else
    {
        for(int i=0;i<A.size();i++)
        {
            if(iscorrect(temp,A[i]))
            {
                temp.push_back(A[i]);
                func(A,ans,temp,index+1);
                temp.pop_back();
            }
        }
    }
}
vector<vector<int> > Solution::permute(vector<int> &A) {
    vector<vector<int>>ans;
    vector<int>temp;
    func(A,ans,temp,0);
    return ans;
}