classSolution: defsearchRange(self, nums: List[int], target: int) -> List[int]: # 取起始下标 l, r = 0, len(nums) - 1 while l < r: mid = (l + r) // 2 if nums[mid] >= target: r = mid else: l = mid + 1
# 没找到 ifnot nums or nums[l] != target: return [-1,-1] # 取结束下标 a, b = 0, len(nums) - 1 while a < b: mid = (a + b) // 2 + 1 if nums[mid] <= target: a = mid else: b = mid - 1 return [l,a]