class Solution {
public int[] searchRange(int[] nums, int target) {
// int[] result = {-1, -1};
int L = 0, R = nums.length - 1, cursor = -1;
while(L <= R)
{
int mid = (L + R) / 2;
if(target > nums[mid])
{
L = mid + 1;
}
else if(target < nums[mid])
{
R = mid - 1;
}
else
{
cursor = mid;
break;
}
}
if(cursor == -1) return new int[]{-1, -1};
int left = cursor;
while(left >= 0 && target == nums[left]) left--;
int right = cursor;
while(right < nums.length && target == nums[right]) right++;
int result[] = {left + 1, right - 1};
return result;
}
}