leetcode -- Find Minimum in Rotated Sorted Array -- 重点
2015-12-10 13:34
531 查看
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/
思路:如果是sorted array,要立马想到 binary search。这里要注意bs的条件。
参考:
http://bookshadow.com/weblog/2014/10/16/leetcode-find-minimum-rotated-sorted-array/
思路:如果是sorted array,要立马想到 binary search。这里要注意bs的条件。
参考:
http://bookshadow.com/weblog/2014/10/16/leetcode-find-minimum-rotated-sorted-array/
class Solution(object): def findMin(self, nums): """ :type nums: List[int] :rtype: int """ ans = nums[0] size = len(nums) low, high = 0, size - 1 while low <= high:#注意这里是小于等于 mid = (low + high) / 2 if nums[mid] <= nums[high]: #min位于上升沿左侧,注意这个条件 high = mid - 1 else: #min位于左侧上升沿与右侧上升沿之间 low = mid + 1 ans = min(ans, nums[mid]) return ans
相关文章推荐
- eclipse中启动服务器正常,地址栏输入访问地址出现500,org.apache.commons.lang.exception.NestableRuntimeException
- php数组函数-array_map()
- oracle 重建索引以及导出所有的索引脚本(可以解决还原数据库文件时先还原数据,在重新用脚本创建索引)
- Android中获取应用程序(包)的信息-----PackageManager的使用
- Remove unnecessary magnetic soft iron calibration parameters on msm8976/8956
- 移动端自动化测试开课了
- Arcgis sde 10.1您不能创建在安装后的空间库,提示User has privileges required to create database objects.
- MySQL中tinytext、text、mediumtext和longtext详解
- C++中的静态绑定和动态绑定
- 利用Java迭代器删除list中元素
- Android页面布局控件-Android学习笔记
- 设计模式之组合模式
- container error log
- POJ 3104 Drying(二分搜索,最大化最小值)
- hdu3306 Another kind of Fibonacci
- 你想不到:咖啡馆里上工具课
- stat用法:获取文件对应权限的数字
- react-native laoding statical image for android rn android平台下加载本地图片
- [BZOJ 1007] [HNOI2008]水平可见直线
- oracle集合查询