统计一个数字在排序数组中出现的次数。
class Solution { public: int GetNumberOfK(vector<int> data ,int k) { if(data.empty()) return 0; return GetNumberOfKCore(data,k+0.5)-GetNumberOfKCore(data,k-0.5); } private: int GetNumberOfKCore(vector<int> data,double k) { int left=0,right=data.size()-1; while(left<=right) { int mid=(right-left)/2+left; if(data[mid]<k) left=mid+1; else if(data[mid]>k) right=mid-1; } return left;//also right } };