35.搜索插入位置-Python-Leetcode
程序员文章站
2022-03-04 19:01:16
...
题目来源
https://leetcode-cn.com/problems/search-insert-position/description/
代码
class Solution:
def searchInsert(self, nums, target):
"""
:type nums: List[int]
:type target: int
:rtype: int
"""
l = len(nums)
flag = False
if nums[0] >= target:
return 0
if nums[l-1] < target:
return l
for i in range(l):
if target == nums[i]:
return i
elif target > nums[i]:
flag = True
elif target < nums[i]:
while flag:
return i
(这是一个数院的菜鸡