n*s 发帖数: 752 | 1 def sSearch(a, v):
tot_len = len(a)
l = 0
r = tot_len-1
while l < r :
m = (l+r) //2
if a[m] > v:
r = m -1
elif a[m] < v:
l = m + 1
else:
r = m # start pointer is saved here
if a[l] is v:
return r
else:
return -1
a = [1,1, 2, 3,3,3,5, 6]
print a
print sSearch(a,3) |
|