feat(792-binary-search): add py3 solution
This commit is contained in:
16
0792_binary-search/python3/solution.py
Normal file
16
0792_binary-search/python3/solution.py
Normal file
@@ -0,0 +1,16 @@
|
||||
class Solution:
|
||||
def search(self, nums: List[int], target: int) -> int:
|
||||
start = 0
|
||||
end = len(nums) - 1
|
||||
|
||||
while start <= end:
|
||||
mid = (start + end) // 2
|
||||
|
||||
if nums[mid] == target:
|
||||
return mid
|
||||
elif target < nums[mid]:
|
||||
end = mid - 1
|
||||
else:
|
||||
start = mid + 1
|
||||
|
||||
return -1
|
||||
Reference in New Issue
Block a user