It's give different result on my local system please help someone


#1

Comment body goes here. static int count = 0;

public int findCount(final int[] A, int B) {
	search(A, B, 0, A.length - 1);
	return count;
}

static void search(final int[] A, int B, int l, int r) {
	int mid = (r + l) / 2;
	if (l == r) {
          if(A[l]==B)
        	  count1(A, B,l);
          return;  
	} 
	else {
		if (A[mid] == B) {
			count1(A, B, mid);
			return;
		} else {
			if (A[mid] > B) {
				search(A, B, l, mid - 1);
			} else {
				search(A, B, mid + 1, r);
			}
		}
	}

}
static void count1(final int[] A, int B,int mid) {
	   int i=mid;
	   while(i>=0 && A[i]==B) {
		   count++;
		   i--;
	   }
	   i=mid+1;
	   while(i<A.length&& A[i]==B ) {
		   count++;
		   i++;
	   }
		   
}

}