public int searchInsert(int[] A, int target) {
int low = 0, high = A.length-1;
while(low<=high){
int mid = (low+high)/2;
if(A[mid] == target) return mid;
else if(A[mid] > target) high = mid-1;
else low = mid+1;
}
return low;
}
public class Solution {
public int searchInsert(int[] nums, int target) {
if (nums == null || nums.length < 1) return 0;
int i = 0;
int j = nums.length - 1;
while (i < j) {
int mid = i + (j - i) / 2;
if (nums[mid] == target) return mid;
else if (nums[mid] < target) {
i = mid + 1;
} else {
j = mid - 1;
}
}
return nums[i] < target ? i + 1 : i;
}
}