标签:搜索 lse turn arch 重复 int type 顺序 输入
class Solution:
def searchInsert(self, nums, target):
"""
:type nums: List[int]
:type target: int
:rtype: int
"""
low = 0
high = len(nums)-1
while low <= high:
mid = (low+high)//2
if target <nums[mid]:
high = mid - 1
elif target > nums[mid]:
low = mid + 1
else:
return mid
return low
a = Solution()
print(a.searchInsert([1,3,5,6],2))
leetcode35题:搜索插入位置(不是最优解法,仅供参考)
标签:搜索 lse turn arch 重复 int type 顺序 输入
原文地址:https://www.cnblogs.com/hello-lwz/p/9440989.html