1 2 3 4 5 6 7 8 9 10 11 12
| def binary_search(arr: list, l_index: int, r_index: int, x): if r_index >= l_index: mid = int(l_index + (r_index - l_index) / 2) if arr[mid] == x: return mid elif arr[mid] > x: return binary_search(arr, l_index, mid - 1, x) else: return binary_search(arr, mid + 1, r_index, x) else: return -1
|