题解 | #数字在升序数组中出现的次数#
https://www.nowcoder.com/practice/70610bf967994b22bb1c26f9ae901fa2
public class Solution { public int GetNumberOfK(int [] array , int k) { int i1 = findK(array,k); int i2 = findK(array,k + 1); if(i1 == i2) return 0; return i2 - i1; } public int findK(int[] array,int k){ int l = 0,r = array.length; while(l < r){ int mid = (l + r) >> 1; if(array[mid] >= k){ r = mid; }else{ l = mid + 1; } } return l; } }