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