【题目解析】
class Solution:
def searchRange(self, nums: List[int], target: int) -> List[int]:
def left_index(nums, target):
l = 0
r = len(nums) - 1
mid = l + (r - l + 1) //2
tag_value = "inf"
while l <= r:
if nums[mid] == target:
tag_value = mid
r = mid - 1
elif nums[mid] < target:
l = mid + 1
else:
r = mid - 1
mid = l + (r - l + 1) // 2
return tag_value if tag_value != "inf" else -1
left_index_value = left_index(nums, target)
tmp_right_index_value = left_index([-1 * i for i in nums[::-1]], -1 * target)
if tmp_right_index_value != -1:
right_index_value = len(nums) - tmp_right_index_value - 1
else:
right_index_value = -1
return [left_index_value, right_index_value]