[leetcode刷题系列]Search Insert Position

依旧是二分基础题, 没啥好说的- -

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


你可能感兴趣的:([leetcode刷题系列]Search Insert Position)