classSolution:""" @param A : a list of integers @param target : an integer to be searched @return : a list of length 2, [index1, index2] """defsearchRange(self,A,target):# write your code hereifA==Noneorlen(A)==0:return[-1,-1]index1=sys.maxintindex2=-1front=0end=len(A)-1# binary search for index1whilefront<=end:mid=(front+end)/2ifA[mid]==target:# if you find target, should check the previous elementend=mid-1ifindex1>mid:index1=midelifA[mid]>target:end=mid-1else:front=mid+1# binary search for index2front=0end=len(A)-1whilefront<=end:mid=(front+end)/2ifA[mid]==target:# if you find target, should check the next elementfront=mid+1ifindex2<mid:index2=midelifA[mid]>target:end=mid-1else:front=mid+1ifindex1==sys.maxintorindex2==-1:return[-1,-1]else:return[index1,index2]