class Solution:
def searchRange(self, nums: List[int], target: int) -> List[int]:
if not nums: return [-1,-1]
left, right = 0, len(nums)-1
while left<=right and nums[left]<target: left+=1
while left<=right and nums[right]>target: right-=1
return [left,right] if left<=right and nums[left]==nums[right]==target else [-1,-1]
【leetcode 34】在排序数组中查找元素的第一个和最后一个位置
原文:https://www.cnblogs.com/wangshujaun/p/14043744.html