Skip to content

Instantly share code, notes, and snippets.

@whiledoing
Created June 9, 2018 09:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whiledoing/f184179a9c820391cb2da06a69e0aa44 to your computer and use it in GitHub Desktop.
Save whiledoing/f184179a9c820391cb2da06a69e0aa44 to your computer and use it in GitHub Desktop.
[python-bisect-left] binary left search implmentation #python #algorithm
def bisect_left(data, v):
left, right = 0, len(data)
while left < right:
mid = (left+right)//2
if v <= data[mid]:
right = mid
else:
left = mid+1
return right
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment