Skip to content

Instantly share code, notes, and snippets.

@dlo
Created April 19, 2010 19:57
Show Gist options
  • Select an option

  • Save dlo/371514 to your computer and use it in GitHub Desktop.

Select an option

Save dlo/371514 to your computer and use it in GitHub Desktop.
def search(n, l):
H = len(l) - 1
L = 0
M = int(H / 2)
while H - L > 1 and n != l[M]:
if n > l[M]:
L = M
else:
H = M
M = int((H + L) / 2)
if n == l[M]:
return M
return -1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment