Intuitive C++ sollution


#1

vector Solution::searchRange(const vector &A, int B) {
int n = A.size(), low = 0, high = n-1, mid;
while(low<high){
mid = low + (high-low)/2;
if(A[mid]>=B){
high = mid;
}
else{
low = mid + 1;
}
}
if(A[low] != B) return {-1, -1};
int start = low;
low = 0; high = n-1;
while(low<high){
mid = low + (high-low+1)/2;
if(A[mid]>B){
high = mid-1;
}
else{
low = mid;
}
}
return {start, low};
}