Search Insert Position
这道题为简单题
题目:

思路:
这道题很简单,直接遍历列表,如果发现该元素不小于目标值,那么就返回该元素的索引,否则返回最后一个元素的索引
代码:
1 class Solution(object): 2 def searchInsert(self, nums, target): 3 """ 4 :type nums: List[int] 5 :type target: int 6 :rtype: int 7 """ 8 a = len(nums) 9 for i in xrange(0, a): 10 if nums[i] >= target: return i 11 return a

浙公网安备 33010602011771号