Simple indented solution, Passes all cases


#1

vector Solution::searchRange(const vector &A, int B) {
int beg = 0;
int end = A.size() - 1;
vector ans(2, -1);
while (beg <= end) {
int mid = (beg + end) / 2;
if (A[mid] == B && (mid == 0 || A[mid - 1] != B))
{
ans[0] = mid;
beg = mid;
end = A.size() - 1;
while (beg <= end) {
mid = (beg + end) / 2;
if (A[mid] == B && (mid == A.size() - 1 || A[mid + 1] != B)) {
ans[1] = mid;
return ans;
}
else if (A[mid] <= B)
beg = mid + 1;
else
end = mid - 1;
}

    }
    else if (A[mid] < B)
        beg = mid + 1;
    else
        end = mid - 1;
}
return ans;

}