题解 | #二分查找-I#
二分查找-I
https://www.nowcoder.com/practice/d3df40bd23594118b57554129cadf47b
from threading import main_thread
class Solution:
def search(self , nums: List[int], target: int) -> int:
st=0
en=len(nums)
if len(nums)==0:
return -1
while st<en:
mid=(en+st)//2
if nums[mid]>=target:
en=mid
else:
st=mid+1
if nums[st]==target:
return st
else:
return -1
#二分模板#