Update BinarySearch.java
This commit is contained in:
@@ -90,4 +90,30 @@ class BinarySearch {
|
||||
}
|
||||
return candidate;
|
||||
}
|
||||
|
||||
public static int binarySearchLeftMost0(int[] nums, int target) {
|
||||
int i = 0, j = nums.length - 1;
|
||||
while (i <= j) {
|
||||
int m = (i + j) >>> 1;
|
||||
if (target < nums[m]) {
|
||||
j = m - 1;
|
||||
} else {
|
||||
i = m + 1;
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
public static int binarySearchRightMost0(int[] nums, int target) {
|
||||
int i = 0, j = nums.length - 1;
|
||||
while (i <= j) {
|
||||
int m = (i + j) >>> 1;
|
||||
if (target < nums[m]) {
|
||||
j = m - 1;
|
||||
} else {
|
||||
i = m + 1;
|
||||
}
|
||||
}
|
||||
return i - 1;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user