查找第一个大于等于目标值的元素下标
public int findFirstBigger(int[] nums, int target){
int l = 0;
int r = nums.length-1;
while(l<r){
int m = l+(r-l)/2;
if(nums[m] >= target) r=m;
else l = m+1;
}
return l;
}
查找最后一个小于等于目标值的元素下标
public int findFirstBigger(int[] nums, int target){
int l = 0;
int r = nums.length-1;
while(l<r){
int m = l+(r-l+1)/2;
if(nums[m] <= target) l=m;
else r = m-1;
}
return l;
}