C++ | Diffk | O(n log n) using lower_bound


#1
int Solution::diffPossible(vector<int> &A, int B) {
    for(int i=0; i<A.size(); i++) {
        int j = (lower_bound(A.begin() + j, A.end(), A[i]+B) - A.begin());
        if(j == i) j ++;
        if(A[j] - A[i] == B)    return true;
    }
    return false;
}