Easy neat and clean code


#1
public class Solution {
// DO NOT MODIFY THE ARGUMENTS WITH "final" PREFIX. IT IS READ ONLY
public int findCount(final int[] X, int tar) {
    int ind=BS(X,tar,0,X.length);
    if(ind==-1)return 0;
    
    int count =1;
    
    int left=ind-1;
    while(left>=0 && X[left--]==tar)count++;
    
    int right=ind+1;
    while(right<X.length && X[right++]==tar)count++;
    
    return count;
}

public static int BS(int X[],int tar,int a,int b)
{
if(a<=b)
{
int mid=a + (b-a) /2;

	if(X[mid]==tar)return mid;
	else if(X[mid]>tar)return BS(X,tar,a,mid-1);
    else return BS(X,tar,mid+1,b);
    
	}
	else return -1;
		
	
	
}

}