def searchRange(self, nums, target):
def binarySearchLeft(A, x):
left, right = 0, len(A)  1
while left <= right:
mid = (left + right) / 2
if x > A[mid]: left = mid + 1
else: right = mid  1
return left
def binarySearchRight(A, x):
left, right = 0, len(A)  1
while left <= right:
mid = (left + right) / 2
if x >= A[mid]: left = mid + 1
else: right = mid  1
return right
left, right = binarySearchLeft(nums, target), binarySearchRight(nums, target)
return (left, right) if left <= right else [1, 1]
16line Python solution, symmetric and clean binary search, 52ms


@kitt
maybe betterdef searchRange(self,nums, target): """ :type nums: List[int] :type target: int :rtype: List[int] """ if target not in nums: return [1,1] l=0 r=len(nums)1 while l<=r and l<len(nums)1 and r>0: if nums[l]!=target: l+=1 if nums[r]!=target: r=1 if nums[l]==target and nums[r]==target: break if nums[l]==target: return [l,r] else: return [1,1]
