new tasks
This commit is contained in:
parent
2a4d27cea0
commit
80737d5a6a
1194 changed files with 15353 additions and 1 deletions
10
Task/Binary_search/Python/binary_search-2.py
Normal file
10
Task/Binary_search/Python/binary_search-2.py
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
def binary_search(l, value, low = 0, high = -1):
|
||||
if not l: return -1
|
||||
if(high == -1): high = len(l)-1
|
||||
if low == high:
|
||||
if l[low] == value: return low
|
||||
else: return -1
|
||||
mid = (low+high)//2
|
||||
if l[mid] > value: return binary_search(l, value, low, mid-1)
|
||||
elif l[mid] < value: return binary_search(l, value, mid+1, high)
|
||||
else: return mid
|
||||
Loading…
Add table
Add a link
Reference in a new issue