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