VV simple C++ soln


#1
int FirstLast(const vector<int> &A, int B, bool first){
    int low = 0, high = A.size()-1, result = -1;
    while(low <= high){
        int mid = (low + high) / 2;
        if(A[mid] == B){
            result = mid;
            if(first)
                high = mid-1;
            else low = mid+1;
        }
        else if(A[mid] < B){
            low = mid+1;
        }
        else high = mid-1;
    }
    return result;
}

int Solution::findCount(const vector<int> &A, int B) {
    int first = FirstLast(A, B, true);
    int last = FirstLast(A, B, false);
    if(first == -1 && last == -1) return 0;
    else return (last-first+1);
}