Skip to content

Commit e6bec94

Browse files
authored
Merge pull request darkprinx#27 from ulmasovjafarbek/patch-2
Binary Search solution
2 parents a812c56 + 19107af commit e6bec94

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

Status/Day_17.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,26 @@ print bin_search(li,12)
125125
#to be written
126126

127127
```
128-
128+
**Solution by ulmasovjafarbek: Python 3**
129+
```python
130+
def binary_search(lst, item):
131+
low = 0
132+
high = len(lst) - 1
133+
134+
while low <= high:
135+
mid = round((low + high) / 2)
136+
137+
if lst[mid] == item:
138+
return mid
139+
elif lst[mid] > item:
140+
high = mid - 1
141+
else:
142+
low = mid + 1
143+
return None
144+
145+
lst = [1,3,5,7,]
146+
print(binary_search(lst, 9))
147+
```
129148
---
130149

131150
**Solution by AasaiAlangaram: Python 3**

0 commit comments

Comments
 (0)