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
LeetCode-35.搜索插入位置(Python)
最新推荐文章于 2024-11-14 23:35:31 发布