Skip to content

Commit 98effb9

Browse files
authored
Create Binary Search.py
1 parent 55338de commit 98effb9

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

Binary Search.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution:
2+
def search(self, nums: List[int], target: int) -> int:
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+
if nums[mid] < target:
10+
low = mid + 1
11+
else:
12+
high = mid - 1
13+
return -1

0 commit comments

Comments
 (0)