class Solution {
public:
int searchInsert(int A[], int n, int target) {
if(n==0)
return 0;
if(n==1)
{
if(target==A[0])
return 0;
if(target>A[0])
{
return 1;
}
if(target<A[0])
{
return 0;
}
}
int low=0;
int high=n;
int mid;
while(low<=high)
{
if(low==high)
return low;
mid=low+(high-low)/2;//避免low+high的值过大
if(A[mid]<target)
low=mid+1;
else//这里的情况包含Mid里的数值小于或者等于target的情况,所以high不能赋值为mid-1
high=mid;
}
}
};