描述
image.png直观解法
class Solution:
def searchInsert(self, nums: List[int], target: int) -> int:
for i in range(len(nums)):
if nums[i] >= target:
return i
elif nums[len(nums)-1] < target:
return len(nums)
简单语句解法:返回的值等于数组中小于target的个数
res = [i for i in nums if i<target]
return len(res)
网友评论