class Solution {//简单的二分搜索变形
public:
int searchInsert(int A[], int n, int target)
{
int low=0;
int high=n-1;
int mid;
while(low<=high)
{
mid=low+((high-low)>>1);
if(A[mid]==target)
return mid;
else if(A[mid]>target)
high=mid-1;
else
low=mid+1;
}
return low;
}
};
LeetCode-Search Insert Position
最新推荐文章于 2024-03-25 23:05:15 发布