# Why "Output Limit Exceeded "

• I think it's O(n^2) complexity, but why it is always rejected with "Output Limit Exceeded"? anyone could help?

``````vector<vector<int> > threeSum(vector<int> &num) {
int total = num.size();
vector< vector<int> > res;

sort(num.begin(),num.end());

for(int i = 0; i<total; ++ i)
{
if(i>0 && num[i] == num[i-1])
continue;
if(num[i] >0)
break;

int j= i+1;
int k = total-1;
vector<int> r;
while(j<k)
{
if(j>i+1 && num[j-1] == num[j])
{
++j;
continue;
}
if(k<total-1 && num[k] == num[k+1])
{
--k;
continue;
}
int sum = num[i]+num[j] + num[k];
if(sum == 0)
{
r.push_back(num[i]);
r.push_back(num[j]);
r.push_back(num[k]);
res.push_back(r);
++j;
--k;
}
else if(sum<0)
{
if(num[k]<=0 || -sum>num[k])
break;
++j;
}
else
{
if(num[j]>=0 || -sum > num[j])
break;
--k;
}
}
}
return res;
}``````

• This post is deleted!

• Your answer size is more than the expected output size .

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