Search Insert Position/easy/day10

题目:

Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.

You may assume no duplicates in the array.

Example 1:

Input: [1,3,5,6], 5
Output: 2

Example 2:

Input: [1,3,5,6], 2
Output: 1

我的解法

 for i,num in enumerate(nums):
            if num >= target:
                return i

        return len(nums)

//感觉python去处理都变得很简单,去复习二分查找,另外记录

猜你喜欢

转载自blog.csdn.net/u010969088/article/details/80004148