Skip to content

Commit 5b79d30

Browse files
authored
Create Code.md
1 parent 2919f77 commit 5b79d30

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

Color-Picker/Code.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
```
2+
def binary_search(arr, target):
3+
low = 0
4+
high = len(arr) - 1
5+
6+
while low <= high:
7+
mid = (low + high) // 2
8+
9+
if arr[mid] == target:
10+
return mid
11+
elif target < arr[mid]:
12+
high = mid - 1
13+
else:
14+
low = mid + 1
15+
16+
return -1
17+
18+
19+
if __name__ == "__main__":
20+
sample = [5, 12, 18, 25, 32, 40, 47]
21+
target = 32
22+
23+
result = binary_search(sample, target)
24+
25+
if result != -1:
26+
print("Element found at index:", result)
27+
else:
28+
print("Element not found")
29+
```

0 commit comments

Comments
 (0)