算法要求:
- 必须采用顺序存储结构。
- 必须按关键字大小有序排列。
class Solution:
def search(self , nums: List[int], target: int) -> int:
# write code here
length = len(nums)
left = 0
right = length - 1
while not nums:
return -1
while nums:
mid = (left + right)//2
if nums[mid] == target:
return mid
elif nums[mid] > target:
right = mid - 1
elif nums[mid] < target:
left = mid + 1
return -1