Why is my code wrong? Using STL-lower_bound,upper_bound


#1

int Solution::search(const vector &A, int B) {
int a=upper_bound(A.begin(),A.end(),B)-A.begin();
int b=lower_bound(A.begin(),A.end(),B)-A.begin();
// cout<<a<<" "<<b<<endl;
if(A[a]==B){
return a;
}
if(A[b]==B){
return b;
}
return -1;
}


#2
I guess the vector should already be sorted for the functions to work properly.

#3

Thanks for pointing it out @f20170200