Find Minimum in Rotated Sorted Array
2015-07-13 20:25
239 查看
题目:
Supposeasortedarrayisrotatedatsomepivotunknowntoyoubeforehand.
(i.e.,
Findtheminimumelement.
Youmayassumenoduplicateexistsinthearray.
代码:九章算法的模板
Supposeasortedarrayisrotatedatsomepivotunknowntoyoubeforehand.
(i.e.,
0124567mightbecome
4567012).
Findtheminimumelement.
Youmayassumenoduplicateexistsinthearray.
代码:九章算法的模板
publicclassSolution{ publicintfindMin(int[]nums) { intstart=0; intend=nums.length-1; while(start+1<end) { intmid=start+(end-start)/2; if(nums[mid]>=nums[end])start=mid; elseend=mid; } if(nums[start]>=nums[end])returnnums[end]; elsereturnnums[start]; } }
相关文章推荐
- jQuery插件开发之boxScroll与marquee
- Android 开源框架ImageLoader基本介绍及使用
- 单源最短路径——Bellman--Ford算法
- const形参的函数重载
- easyui中datagrid和layout的问题
- DataTable数据转换为实体
- 介绍Google App Engine
- leetcode 027 —— Remove Element
- Node:普通归并
- 英格兰、威尔士、北爱尔兰教育体系
- 使用const关键字进行函数重载
- POJ 2886 Who Gets the Most Candies?(线段树·约瑟夫环)
- 第一篇博客
- POJ 2481 Cows
- Gym 100496A Avangard Latin Squares(矩阵游戏)
- JSP 标准标签库(JSTL)之最常用的JSTL标签总结
- const型变量与函数重载
- CXF WebService整合Spring
- 算法导论 第五章:随机算法
- 类的const和非const成员函数的重载