您的位置:首页 > 其它

[leetcode刷题系列]Search Insert Position

2013-08-04 20:35 363 查看
依旧是二分基础题, 没啥好说的- -

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 low = 0, high = n - 1, mid;
while(low <= high)
if(A[mid = low + high >> 1] >=  target) high = mid - 1;else low = mid + 1;
return low;
}
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: