You are viewing a single comment's thread. Return to all comments →
C++:
long pairs(long k, vector array) { long count = 0,temp; std::sort(array.begin(),array.end());
for(int i=0;i<array.size();i++){ for(int j=i+1;j<array.size();j++){ if(array[j]-array[i]==k){ count++; } if((array[j]-array[i])>k){ ++i; j = i; continue; } } }
return count;
}
Seems like cookies are disabled on this browser, please enable them to open this website
Pairs
You are viewing a single comment's thread. Return to all comments →
C++:
long pairs(long k, vector array) { long count = 0,temp; std::sort(array.begin(),array.end());
return count;
}