publicclassSolution { /** * @param A: A an integer array sorted in ascending order * @param target: An integer * @return: An integer */publicinttotalOccurrence(int[] A,int target) {if (A ==null||A.length==0) {return0; }int start, end;int left =0, right =A.length-1;// find left end point of the rangewhile (left +1< right) {int mid = left + (right - left) /2;if (A[mid] < target) { left = mid; } else { right = mid; } }if (A[left] == target) { start = left; } elseif (A[right] == target) { start = right; } else {return0; }// find right end point of the range left =0; right =A.length-1;while (left +1< right) {int mid = left + (right - left) /2;if (A[mid] > target) { right = mid; } else { left = mid; } }if (A[right] == target) { end = right; } elseif (A[left] == target) { end = left; } else {return0; }return end - start +1; }}