class Solution {
public:
int GetIndex(vector<int> data, int k){
if(data.size() == 0)
return 0;
int left = 0, right = data.size() -1;
int mid = (left + right) / 2;
if(data[mid] > k){
right = mid -1;
}else if (data[mid] < k){
left = mid + 1;
}else{
if(data[mid-1] < k)
return mid;
else if(data[mid-1]==k){
right = mid-1;
}
}
//return 0;
return GetIndex(vector<int>(data.begin()+left, data.end()-(data.size()-right-1)), k) + left;
}
int GetNumberOfK(vector<int> data ,int k) {
if(data.size() == 0)
return 0;
int idx = GetIndex(data, k);
int count = 0;
for(int i = idx; i < data.size(); i++)
if(data[i] == k)
count ++;
else{
break;
}
//cout << count << endl;
return count;
}
};