元素中有重复的二分查找
class Solution {
public int[] searchRange(int[] nums, int target) {
int left_index=-1;
int right_index=-1;
int left=0;
int right=nums.length-1;
while(left<right){
int mid =left+(right-left)/2;
if(target<nums[mid])
right=mid-1;
else if(target>nums[mid])
left=mid+1;
else
right=mid;
}
if(left<nums.length&&nums[left]==target)
left_index=left;
left=0;
right=nums.length-1;
while(left<right){
int mid =left+(right-left+1)/2;
if(target>nums[mid])
left=mid+1;
else if(target<nums[mid])
right=mid-1;
else
left=mid;
}
if(left<nums.length&&nums[left]==target)
right_index=left;
return new int[]{left_index,right_index};
}
}