1
var searchRange = function (nums, target) {2
if (nums.length === 1) return nums[0] === target ? [0, 0] : [-1, -1];4
const findFirstInstance = (left, right) => {5
if (left === right) return left;8
if (left === pivot) left += 1;9
pivot = Math.floor((left + right) / 2);10
if (nums[pivot] === target) {11
if (nums[pivot - 1] !== target) return pivot;12
return findFirstInstance(left, pivot - 1);14
if (nums[pivot] > target) right = pivot;18
const findLastInstance = (left, right) => {19
if (left === right) return left;21
while (left < right) {22
if (left === pivot) left += 1;23
pivot = Math.floor((left + right) / 2);24
if (nums[pivot] === target) {25
if (nums[pivot + 1] !== target) return pivot;26
return findLastInstance(pivot + 1, right);28
if (nums[pivot] > target) right = pivot;34
right = nums.length - 1,37
while (left < right) {38
if (left === pivot) left += 1;39
pivot = Math.floor((left + right) / 2);40
if (nums[pivot] === target) {42
nums[pivot - 1] !== target ? pivot : findFirstInstance(left, pivot - 1);44
nums[pivot + 1] !== target ? pivot : findLastInstance(pivot + 1, right);47
if (nums[pivot] > target) right = pivot;