class Solution {
public:
int searchInsert(int A[], int n, int target) {
int length = n;
int mid = 0;
int first = 0;
while(length)
{
int half = length>>2;
int mid = first + half;
if(A[mid]>target){
length = half;
}
else if(A[mid]<target)
{
first = mid+1;
length = length-half-1;
}
else
{//target == A[mid]
return mid;
}
}
return first;
}
};
lower bound and upper bound is only different when find the target == A[mid];
for lower bound ;search for the left side again;
for the upper bound; search for the right side;