public int searchInsert(int[] A, int target) {
    	if (A.length == 0 || target < A[0])
    		return 0;
    	else if (target > A[A.length - 1])
    		return A.length;
    	
    	int start = 0;
    	int end = A.length - 1;
    	while (start < end)
    	{
    		int mid = (start + end) / 2;
    		if (A[mid] == target)
    			return mid;
    		else if (A[mid] > target)
    			end = mid;
    		else
    			start = mid + 1;
    	}
    	
   		return start; 
    }