tests/java/src/searchInsertPosition/searchInsertPosition.java
private int searchInsertI(int[] nums, int target) {
         if (nums == null || nums.length == 0) {
            return 0;
        }

        int start = 0;
        int end = nums.length - 1;

        while (start + 1 < end) {
            int mid = start + (end - start) / 2;
            if (nums[mid] == target) {
                return mid;
            } else if (nums[mid] < target) {
                start = mid;
            } else {
                end = mid;
            }
        }

        if (nums[start] >= target) {
            return start;
        }
        if (nums[end] >= target) {
            return end;
        }
        return end + 1;
    }
// Find the first position >= target
Find the first position >= target
Find the first position > = target
private int searchInsertI(int[] nums, int target) {
         if (nums == null || nums.length == 0) {
            return 0;
        }
        int start = 0;
        int end = nums.length - 1;
        while (start + 1 < end) {
            int mid = start + (end - start) / 2;
            if (nums[mid] == target) {
                return mid;
            } else if (nums[mid] < target) {
                start = mid;
            } else {
                end = mid;
            }
        }
        if (nums[start] >= target) {
            return start;
        }
        if (nums[end] >= target) {
            return end;
        }
        return end + 1;
    }
private int searchInsertI ( int [ ] nums , int target ) { if ( nums == null || nums . length == 0 ) { return 0 ; } int start = 0 ; int end = nums . length - 1 ; while ( start + 1 < end ) { int mid = start + ( end - start ) / 2 ; if ( nums [ mid ] == target ) { return mid ; } else if ( nums [ mid ] < target ) { start = mid ; } else { end = mid ; } } if ( nums [ start ] >= target ) { return start ; } if ( nums [ end ] >= target ) { return end ; } return end + 1 ; }
Find the first position >= target
Find the first position > = target