Simple C++ using lower_bound and upper_bound of stl

Simple C++ code

vector<int> Solution::searchRange(const vector<int> &A, int B) {
    if(binary_search(A.begin(),A.end(),B))
    {
        return {lower_bound(A.begin(),A.end(),B)-A.begin(),upper_bound(A.begin(),A.end(),B)-A.begin()-1};
    }
    return {-1,-1};
}
1 Like
Click here to start solving coding interview questions