用二分查找的思想
注意最后返回的left right 会出错
class Solution {
public:
int searchInsert(int A[], int n, int target) {
int left=0;
int right=n-1;
while(left<=right){
int mid=left+(right-left)/2;
if(A[mid]==target)
return mid;
else if(A[mid]>target)
right=mid-1;
else if(A[mid]<target)
left=mid+1;
}
return left;
}
};