二分
class Solution {
public:
int getNumberOfK(vector<int>& nums , int k) {
if(nums.size() == 0)
return 0;
int l = 0, r = nums.size()-1;
while(l < r)
{
int mid = l + r >> 1;
if(nums[mid] >= k)
r = mid;
else
l = mid + 1;
}
int res = 0;
while(nums[r] == k)
{
res++;
r++;
}
return res;
}
};