Tony's Log

Algorithms, Distributed System, Machine Learning

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

A simple 1D searching problem. Binary search of course.

But.. STL has already done it for you:

class Solution {
public:
    int searchInsert(int A[], int n, int target) {
        int *p = std::lower_bound(A, A+n, target); 
        return p - A;
    }
};
posted on 2014-07-18 13:51  Tonix  阅读(93)  评论(0编辑  收藏  举报