You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
if (maxIndex<=0 || array[maxIndex-1] <= x) returnmaxIndex;
95
75
intleft = 0;
96
76
intright = maxIndex-1;
@@ -111,22 +91,34 @@ public int getInsertPosition_v1(byte[] array, int maxIndex, byte x) {
111
91
}
112
92
returnleft;
113
93
}
114
-
94
+
115
95
/**
116
96
* Find the insert position for x into array given that array is sorted bottom-up.
117
97
*
118
-
* More precisely:
119
-
* If array[maxIndex-1] > x, return the index of the first entry of array[0].. array[maxIndex-1] greater than x.
120
-
* If array[maxIndex-1] <= x, return maxIndex.
121
-
*
122
-
* Faster version using Arrays.binarySearch().
98
+
* This version is faster than getPreciseInsertPosition(), but "If the range contains multiple elements with the specified value, there is no guarantee which one will be found."
123
99
*
124
100
* @param array
125
101
* @param maxIndex the maximum index to consider, exclusive (may be smaller than the array size)
inti = Arrays.binarySearch(array, 0, maxIndex, x);
108
+
returni >= 0 ? i + 1 : -i - 1;
109
+
}
110
+
111
+
/**
112
+
* Find the insert position for x into array given that array is sorted bottom-up.
113
+
*
114
+
* This version is faster than getPreciseInsertPosition(), but "If the range contains multiple elements with the specified value, there is no guarantee which one will be found."
115
+
*
116
+
* @param array
117
+
* @param maxIndex the maximum index to consider, but "If the range contains multiple elements with the specified value, there is no guarantee which one will be found."
0 commit comments