leetcode Search Insert Position
class Solution {
public:
int searchInsert(int A[], int n, int target)
{
int low=0,high=n-1;
int m=0;
if(A[0]>target)return 0;
while(low<=high)
{
m=low+(high-low)/2;
if(A[m]==target)return m;
if(A[m]>target)
{
high=m-1;
}
if(A[m]<target)
{
low=m+1;
}
}
return low;
}
};
浙公网安备 33010602011771号