classMySolutionOffer53I{ publicintsearch(int[] nums, int target){ int count = 0; if (nums==null||nums.length==0) return count; int index0 = BinarySearch(nums, 0, nums.length, target); if (index0>=nums.length||nums[index0]!=target) return count; int index1 = BinarySearch(nums,index0,nums.length,target+1); return index1-index0; } // array[first, last); array[index]>=value staticintBinarySearch(int []array, int first, int last, int value) { while (first<last) { int mid = first+(last-first)/2; if (array[mid]<value) first = mid+1; else last=mid; } return first; //or last. } }