首页 > 代码库 > LeetCode "Search Insert Position"

LeetCode "Search Insert Position"

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;    }};