Skip to content

Instantly share code, notes, and snippets.

@maksadbek
Last active May 25, 2019 21:34
Show Gist options
  • Save maksadbek/9d66c2c93c7d2379e290ac90e3a49f9c to your computer and use it in GitHub Desktop.
Save maksadbek/9d66c2c93c7d2379e290ac90e3a49f9c to your computer and use it in GitHub Desktop.
def search(arr, l, r, x):
if r >= l:
mid = int(l + (r - l)/2)
if len(arr) <= mid:
return mid
if arr[mid] == x:
return r, mid
elif arr[mid] > x:
return search(arr, l, mid-1, x)
else:
return search(arr, mid + 1, r, x)
else:
return -1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment