This would a good approach by using two pointers


#1

int n=A.size();
if(n<=1){
return 0;
}
sort(A.begin(),A.end());
int i=0;
int j=1;
while(i<j && j<n && i<n){
if((A[j]-A[i])==B){
return 1;
}
else if((A[j]-A[i])<B){
j++;
}
else{
i++;
if(i==j){
j++;
}

    }
}
return 0;