35. Search Insert Position leetcode Python 2016 new season
2016-01-20 11:01
591 查看
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.
Here are few examples.
Show Tags
Show Similar Problems
You may assume no duplicates in the array.
Here are few examples.
[1,3,5,6], 5 → 2
[1,3,5,6], 2 → 1
[1,3,5,6], 7 → 4
[1,3,5,6], 0 → 0
Show Tags
Show Similar Problems
class Solution(object): def searchInsert(self, nums, target): """ :type nums: List[int] :type target: int :rtype: int """ low = 0 high = len(nums) - 1 while low <= high: mid = low + (high - low) / 2 if nums[mid] < target: low = mid + 1 elif nums[mid] > target: high = mid - 1 else: return mid return low
相关文章推荐
- 编写Python爬虫抓取豆瓣电影TOP100及用户头像的方法
- 自学Python十 爬虫实战三(美女福利续)
- 34. Search for a Range leetcode Python 2016 new season
- 转来的--轻松自动化---selenium-webdriver(python) (七)---定位iframe——转来的
- 以视频爬取实例讲解Python爬虫神器Beautiful Soup用法
- python 装饰器之示例讲解
- Python算法题----1到100求和的3种加法
- Python算法题----最大公约数
- pickle-python数据持久存储
- Windows环境下Python v2.7.9,Notepad++编写程序中涉及中文,执行时CMD中显示乱码的解决办法
- 使用Python的urllib和urllib2模块制作爬虫的实例教程
- Python算法题----孙悟空吃蟠桃
- python三大神器之一fabric使用
- python (3)简单语法:字符串(strip函数),数据类型
- Python自动化面试必备 之 你真明白装饰器么?
- python语法
- python 使用thrift序列化与反序列化对象
- Python脚本后台运行的几种方式
- 【LEETCODE】73-Set Matrix Zeroes [Python]
- python django runserver errno 10013