class Solution:
def searchInsert(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
elif nums[mid] < target:
left = mid+ 1
else:
right = mid- 1
return right + 1
二分查找-力扣35
最新推荐文章于 2024-11-04 12:20:00 发布