数据结构算法操作试题(C++/Python)——搜索插入位置

文章目录


数据结构算法操作试题(C++/Python):数据结构算法操作试题(C++/Python)——目录


1. 题目

leetcode 链接:https://leetcode-cn.com/problems/search-insert-position/
在这里插入图片描述

2. 解答

python:24ms, 10.9MB, 99%

class Solution(object):
    def searchInsert(self, nums, target):
        """ :type nums: List[int] :type target: int :rtype: int """
        i = -1
        for i in range(len(nums)):
            if nums[i] >= target: return i
        return i + 1

其他方法看 leetcode 链接 评论区~