leetcode——35.搜索插入位置

 1 class Solution:
 2     def searchInsert(self, nums, target: int) -> int:
 3         if target in nums:
 4             return nums.index(target)
 5         else:
 6             if target>=nums[-1]:
 7                 return len(nums)
 8             if target<nums[0]:
 9                 return 0
10             for i in range(len(nums)):
11                 if target>=nums[i] and target<nums[i+1]:
12                     return i+1
执行用时 :88 ms, 在所有 Python3 提交中击败了26.55%的用户
内存消耗 :14.2 MB, 在所有 Python3 提交中击败了5.47%的用户
 
                                                                                                ——  2019.9.24

猜你喜欢

转载自www.cnblogs.com/taoyuxin/p/11577016.html