Simple easy C++ solution

facebook
programming
Tags: #<Tag:0x00007f24254baac8> #<Tag:0x00007f24254ba988>

#1

int Solution::diffPossible(vector &A, int B) {

int n=A.size();

if(n<=1){
    return 0;
}

int i=0;
int j=n-1;
int diff;

for(int i=0;i<n;i++){
    j=n-1;
    while(j!=i){
        diff=A[j]-A[i];
        if(B < diff){
            j--;
        }else if(B == diff){
            return 1;
        }else{
            break;
        }
    }
}

return 0;

}