https://leetcode.com/problems/search-for-a-range/description/
class Solution(object):
def searchRange(self, nums, target):
"""
:type nums: List[int]
:type target: int
:rtype: List[int]
"""
start=0
end=len(nums)-1
while start<=end:
half = (start+end)/2
if target<=nums[half]:
end=half-1
else:
start=half+1
if start<len(nums) and nums[start] == target:
pos0=start
elif start+1 < len(nums) and nums[start+1] == target:
pos0=start+1
else:
return [-1, -1]
start=pos0
end=len(nums)-1
while start<=end:
half = (start+end)/2
if target>=nums[half]:
start=half+1
else:
end=half-1
if start < len(nums) and nums[start] == target:
pos1=start
else:
pos1=start-1
return [pos0, pos1]