class Solution:
def searchRange(self, nums: List[int], target: int) -> List[int]:
if not nums:
return [-1, -1]
left = 0
length = len(nums)
right = length
result = []
while left < right:
mid = (left + right) // 2
if nums[mid] == target:
right = mid
elif nums[mid] < target:
left = mid + 1
else:
right = mid
if left == length or nums[left] != target:
return [-1,-1]
else:
result.append(left)
while left < length and nums[left] == target:
left+=1
result.append(left-1)
return result
二分法简单方便理解,但是执行效率有点低,有时间再看看优化