public class Solution {
public int GetNumberOfK(int [] array , int k) {
if(array == null || array.length == 0) {
return 0;
}
int le = 0, ri = array.length - 1, mid = 0;
while(le < ri) {
mid = (le + ri) / 2;
if(array[mid] == k) {
break;
} else if(array[mid] > k) {
ri = mid - 1;
} else {
le = mid + 1;
}
}
if(array[mid] != k) {
return 0;
}
le = mid;
while(le > -1 && array[le] == k) le--;
ri = mid;
while(ri < array.length && array[ri] == k) ri++;
return ri - 1 - le;
}
}