class Solution {
public int[] searchRange(int[] nums, int target) {
int i = left(nums, target);
int j = right(nums, target);
return new int[] { i, j };
}
public int right(int[] arr, int target) {
int i = 0, j = arr.length - 1;
int candi = -1;
int mid;
while (i <= j) {
mid = (i + j) >>> 1;
if (arr[mid] > target) {
j = mid - 1;
} else if (arr[mid] < target) {
i = mid + 1;
} else {
candi = mid;
i = mid + 1;
}
}
return candi;
}
public int left(int[] arr, int target) {
int i = 0, j = arr.length - 1;
int candi = -1;
int mid;
while (i <= j) {
mid = (i + j) >>> 1;
if (arr[mid] > target) {
j = mid - 1;
} else if (arr[mid] < target) {
i = mid + 1;
} else {
candi = mid;
j = mid - 1;
}
}
return candi;
}
}