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 发布