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
|
||||
8
Task/Binary_search/Python/binary_search-3.py
Normal file
8
Task/Binary_search/Python/binary_search-3.py
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
index = bisect.bisect_left(list, item) # leftmost insertion point
|
||||
index = bisect.bisect_right(list, item) # rightmost insertion point
|
||||
index = bisect.bisect(list, item) # same as bisect_right
|
||||
|
||||
# same as above but actually insert the item into the list at the given place:
|
||||
bisect.insort_left(list, item)
|
||||
bisect.insort_right(list, item)
|
||||
bisect.insort(list, item)
|
||||
9
Task/Binary_search/Python/binary_search.py
Normal file
9
Task/Binary_search/Python/binary_search.py
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
def binary_search(l, value):
|
||||
low = 0
|
||||
high = len(l)-1
|
||||
while low <= high:
|
||||
mid = (low+high)//2
|
||||
if l[mid] > value: high = mid-1
|
||||
elif l[mid] < value: low = mid+1
|
||||
else: return mid
|
||||
return -1
|
||||
Loading…
Add table
Add a link
Reference in a new issue