MCPcopy Create free account
hub / github.com/BeeBombshell/Python-DSA / binary_search

Function binary_search

Search Algorithms/binary_search.py:1–13  ·  view source on GitHub ↗
(self, nums: List[int], target: int)

Source from the content-addressed store, hash-verified

1 def binary_search(self, nums: List[int], target: int) -> int:
2
3 low = 0
4 high = len(nums)-1
5 while low <= high:
6 mid = (low + high) // 2
7 if nums[mid] == target:
8 return mid
9 elif nums[mid] < target :
10 low = mid + 1
11 else:
12 high = mid - 1
13 return -1

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected