序列递增:二分性质
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;
}
if(nums[l] != k) return 0;
int cnt = 0;
for(int i = l; i <= nums.size(); i ++ ){
if(nums[i] == k) cnt ++ ;
else break;
}
return cnt;
}
};