Solution using O(logN) STLs lower_bound, upper_bound and binary_search


#1
vector<int> Solution::searchRange(const vector<int> &A, int B){
    vector<int> res;
    if(binary_search(A.begin(), A.end(), B)){
        int pos1=lower_bound(A.begin(), A.end(), B)-A.begin();
        res.push_back(pos1);
        int pos2= upper_bound(A.begin(), A.end(), B)-A.begin();
        res.push_back(pos2-1);
        return res;
    }
    else{
        res.push_back(-1);
        res.push_back(-1);
        return res;
    }
}
vector<int> Solution::searchRange(const vector<int> &A, int B){
    vector<int> res;
    if(binary_search(A.begin(), A.end(), B)){
        int pos1=lower_bound(A.begin(), A.end(), B)-A.begin();
        res.push_back(pos1);
        int pos2= upper_bound(A.begin(), A.end(), B)-A.begin();
        res.push_back(pos2-1);
        return res;
    }
    else{
        res.push_back(-1);
        res.push_back(-1);
        return res;
    }
}