Recursive Bin_search approach


#1

int bin_search(const vector &A, int B, int start, int end)
{
int mid;
while(start<=end)
{
mid=start+((end-start)/2);
if(A[mid]==B)
return 1+bin_search(A,B,mid+1,end)+bin_search(A,B,start,mid-1);
else if(A[mid]>B)
end=mid-1;
else
start=mid+1;
}
return 0;
}
int Solution::findCount(const vector &A, int B)
{
int n=A.size();
return bin_search(A,B,0,n-1);
}