35.搜索插入位置-Python-Leetcode

题目来源

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

这里写图片描述
(这是一个数院的菜鸡

你可能感兴趣的:(Leetcode)