Runtime: 56 ms, faster than 26.42% of Python3 online submissions for Search Insert Position.
- 如果 target > list最后一个数 那就是插入到最后
- 就是挨个比较
class Solution:
def searchInsert(self, nums, target):
"""
:type nums: List[int]
:type target: int
:rtype: int
"""
i = 0
if target > nums[-1]:
return len(nums)
while(i < len(nums)):
if nums[i] >= target:
return i
i+=1