class Solution {
public:
int searchInsert(int A[], int n, int target) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
int l = 0;
int r = n-1;
while (l <= r)
{
int mid = l+(r-l)/2;
if (A[mid] > target)
r = mid-1;
else if (A[mid] < target)
l = mid+1;
else return mid;
}
return l;
}
};[LeetCode]Search Insert Position
最新推荐文章于 2019-02-13 15:00:16 发布
本文详细介绍了C++中使用二分查找算法实现搜索插入位置的方法,包括关键步骤和代码实现。
512

被折叠的 条评论
为什么被折叠?



