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