class Solution {
public int[] searchRange(int[] nums, int target) {
if (nums.length == 0) return new int[]{-1, -1};
// 搜左边界
int l = 0, r = nums.length - 1;
while (l < r) {
int mid = (l + r) >> 1;
if (nums[mid] >= target) r = mid;
else l = mid + 1;
}
if (nums[l] != target) {
return new int[]{-1, -1};
}
int L = l;
// 搜右边界
l = 0;
r = nums.length - 1;
while (l < r) {
int mid = (l + r + 1) >> 1;
if (nums[mid] > target) r = mid - 1;
else l = mid ;
}
int R = l;
return new int[]{L, R};
}
}
标签:target,nums,int,mid,34,length,查找,new,排序
From: https://www.cnblogs.com/eiffelzero/p/16880357.html