** 直观方法 **
class Solution:
def searchRange(self, nums: List[int], target: int) -> List[int]:
def binarySearch(nums: List[int], target: int) -> int:
l = len(nums)
left,right = 0, l - 1
while left <= right:
mid = left + (right - left) // 2
if nums[mid] > target:
right = mid - 1
elif nums[mid] < target:
left = mid + 1
else:
return mid
return -1
res = binarySearch(nums, target)
left, right = res, res
if res == -1:return [-1, -1]
while left - 1 >= 0 and nums[left - 1] == target: left -= 1
while right + 1 <= len(nums) - 1 and nums[right + 1] == target:right += 1
return [left, right]