Skip to content
Open

list #56

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions README.md

This file was deleted.

15 changes: 15 additions & 0 deletions list
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
def binary_search(arr, target):
left, right = 0, len(arr) - 1
while left <= right:
mid = (left + right) // 2
if arr[mid] == target:
return mid
elif arr[mid] < target:
left = mid + 1
else:
right = mid - 1
return -1

arr = [1, 3, 5, 7, 9]
target = 7
print("Element found at index:", binary_search(arr, target))