package newcoder;
import java.util.Arrays;
public class Solution {
public int[] searchRange(int[] nums, int target) {
int result[]=new int[]{-1,-1};
int index=Arrays.binarySearch(nums, target);
if(index<0)
{
return result;
}
result[0]=index;
result[1]=index;
while(result[0]-1>=0&&nums[result[0]-1]==target)
{
result[0]--;
}
while(result[1]+1<nums.length&&nums[result[1]+1]==target)
{
result[1]++;
}
return result;
}
}
leetcode Search for a Range
最新推荐文章于 2022-07-27 13:46:02 发布