Search Insert Position
本质上是lower_bound,注意其与upper_bound之间的差别
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
int searchInsert(int A[], int n, int target) { //本质上实现lower_bound函数 return lower_bound(A, A + n, target) - A; } template<typename ForwardIterator ,typename T> ForwardIterator lower_bound(ForwardIterator first, ForwardIterator last, T value) { while (first != last) { auto mid = next(first, distance(first, last) / 2); //对于upper_bound:if(value>=*mid) if (value > *mid)first = ++mid; else last = mid; } return first; }