# Why output limit exceeded?

• Here are my codes. I got output limit exceeded. But when i comment the second swap(), and delete the '&' before num, i got accept. Does anybody know why?

//Codes output limit exceeded

class Solution {
public:
vector<vector<int> > permuteUnique(vector<int> &num) {
vector<vector<int> > ans;
sort(num.begin(),num.end());
ite(num,0,ans);
return ans;
}

``````void ite(vector<int>& num,int idx,vector<vector<int>> &result)
{
if(idx==num.size()-1) result.push_back(num);
else
{
for(int i=idx;i<num.size();i++)
{
if(num[idx]==num[i]&&i>idx) continue;
swap(num[idx],num[i]);
ite(num,idx+1,result);
swap(num[idx],num[i]);
}
}
}
``````

};

//Codes accepted

class Solution {
public:
vector<vector<int> > permuteUnique(vector<int> &num) {
vector<vector<int> > ans;
sort(num.begin(),num.end());
ite(num,0,ans);
return ans;
}

``````void ite(vector<int> num,int idx,vector<vector<int>> &result)
{
if(idx==num.size()-1) result.push_back(num);
else
{
for(int i=idx;i<num.size();i++)
{
if(num[idx]==num[i]&&i>idx) continue;
swap(num[idx],num[i]);
ite(num,idx+1,result);
//swap(num[idx],num[i]);
}
}
}
``````

};

• I also got it " Time Limit Exceeded", Had you solved?

• Had you solved this? I also got it and perhaps we use same algorithm.

• mine is code error

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.