Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int Solution::solve(vector<int> &A, int B) {
- int size=A.size(),k=abs(B);
- vector<int> v=A;
- int i=0,j=1;
- sort(v.begin(),v.end());
- while(j<size)
- {
- int diff=v[j]-v[i];
- if(diff<k)
- {
- j++;
- }
- else if(diff>k)
- {
- i++;
- }
- else
- {
- if(diff==k&&i!=j)
- return 1;
- j++;
- }
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment