题目来源 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 lfor i in range(l):
if target == nums[i]:
return i
elif target > nums[i]:
flag = True
elif target < nums[i]:
while flag:
return i
【35.搜索插入位置-Python-Leetcode】

文章图片
(这是一个数院的菜鸡
推荐阅读
- 数据结构与算法|【算法】力扣第 266场周赛
- leetcode|今天开始记录自己的力扣之路
- Python|Python 每日一练 二分查找 搜索旋转排序数组 详解
- 【LeetCode】28.实现strstr() (KMP超详细讲解,sunday解法等五种方法,java实现)
- LeetCode-35-搜索插入位置-C语言
- leetcode python28.实现strStr()35. 搜索插入位置
- Leetcode Permutation I & II
- python|leetcode Longest Substring with At Most Two Distinct Characters 滑动窗口法
- LeetCode 28 Implement strStr() (C,C++,Java,Python)
- Python|Python Leetcode(665.非递减数列)