# Output limit exceed

• Why am I solution is always report output limit exceed.
I follow the 3 sum ,o(n^3).

vector<vector<int> > fourSum(vector<int> &num, int target) {

int size = num.size();
int i;
int j;

vector<vector<int> >result;

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

for(i=0;i<size-3;i++){
if( i > 0 && num[i] == num[i-1] ){
continue;
}

for(j=i+1;j<size-2;j++){
if( j>(i+1) && num[j] == num[j-1]){
continue;
}
int start = j + 1;
int end = size -1;
int target = -(num[i]+num[j]);
while(start<end){
if( num[start] + num[end] == target ){
if((start-1)>j &&num[start] == num[start-1]){
start++;
continue;
}
if( (end+1)<size && num[end] == num[end+1]){
end--;
continue;
}
vector<int>solution(4);
solution[0] = num[i];
solution[1] = num[j];
solution[2] = num[start];
solution[3] = num[end];
result.push_back(solution);
start++;
end--;
}
else if( num[start] + num[end] < target ){
start++;
}
else{
end--;
}
}
}

}

return result;
}

• 你的问题是output limit exceed，不是超时。

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