码迷,mamicode.com
首页 > 其他好文 > 详细

Search Insert Position

时间:2017-09-22 01:03:04      阅读:152      评论:0      收藏:0      [点我收藏+]

标签:int   技术分享   题目   元素   com   sel   xrange   tar   images   

    这道题为简单题

  题目:

    技术分享

 

  思路:

    这道题很简单,直接遍历列表,如果发现该元素不小于目标值,那么就返回该元素的索引,否则返回最后一个元素的索引

  代码:

 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

 

Search Insert Position

标签:int   技术分享   题目   元素   com   sel   xrange   tar   images   

原文地址:http://www.cnblogs.com/liuxinzhi/p/7572139.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!