Easy 9 lines C++


#1
vector<int> Solution::searchRange(const vector<int> &A, int B) {
    auto s = lower_bound(begin(A), end(A), B);
    auto e = upper_bound(begin(A), end(A), B);
    if(*s != B) return {-1, -1};
    else if(*s == B and e != begin(A) and *prev(e) == B) {
        int start = s - begin(A);
        int end = prev(e) - begin(A);
        return {start, end};
    }
    return {-1, -1};
}