首页 > 代码库 > LeetCode Search Insert Position

LeetCode Search Insert Position

class Solution {public:    int searchInsert(int A[], int n, int target) {        if (A == NULL || n < 1) return 0;        int p = -1, q = n;        while (p + 1 < q) {            int mi = (p + q) / 2;            if (A[mi] > target) {                q = mi;            } else if (A[mi] < target) {                p = mi;            } else {                return mi;            }        }        return q;    }};

水一发,第一道一两分钟搞定的题,好像已经会背了