思想
例题
例题一
简单的二分搜索,如下是本题的代码:
class Solution:
def search(self, nums: List[int], target: int) -> int:
left,right = 0,len(nums)-1
while(left <= right):
mid = (left+right) // 2
if nums[mid] == target:
return mid
if nums[mid] < target:
left = mid+1
else:
right = mid-1
return -1