public int searchInsert(int[] A, int target) {
        // write your code here
        if (A == null || A.length == 0)
            return 0;
        int begin = 0, end = A.length - 1;
        while (begin + 1 < end) {
            int mid = begin + (end - begin) / 2;
            int val = A[mid];
            if (val == target)
                return mid;
            else if (val < target)
                begin = mid;
            else
                end = mid;
        }
        if (A[begin] >= target)
            return begin;
        else if (A[end] >= target)
            return end;
        else
            return end + 1;
    }