旋转数组的最小数字
来源:互联网 发布:linux根目录介绍 编辑:程序博客网 时间:2024/06/04 00:40
把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转。输入一个递增排序的数组的一个旋转,输出旋转数组的最小元素。例如数组{3,4,5,1,2}为{1,2,3,4,5}的一个旋转,该数组的最小值为1。
class Solution {public: int minNumberInRotateArray(vector<int> rotateArray) { int start=0; int end=rotateArray.size()-1; while(start<=end){ int middle=(start+end)/2; if(rotateArray[middle]<=rotateArray[end]){ if(rotateArray[start]<=rotateArray[middle]){ int min=INT_MAX; for(int i=start;i<=end;i++){ if(min>rotateArray[i]) min=rotateArray[i]; } return min; } else{ end=middle; } } else{ start=middle+1; } } if(rotateArray.size()!=0) return rotateArray[start]; else return 0; }};
0 0
- 旋转数组的最小数字
- 旋转数组的最小数字
- 旋转数组的最小数字
- 旋转数组的最小数字
- 旋转数组的最小数字
- 旋转数组的最小数字
- 旋转数组的最小数字
- 旋转数组的最小数字
- 旋转数组的最小数字
- 旋转数组的最小数字
- 旋转数组的最小数字
- 旋转数组的最小数字
- 旋转数组的最小数字
- 旋转数组的最小数字
- 旋转数组的最小数字
- 旋转数组的最小数字
- 旋转数组的最小数字
- 旋转数组的最小数字
- DOM解析
- 用两个栈实现队列
- 新建Microsoft Word文档 (优先队列,模拟好像会T)
- 使用注解描述的Servlet程序开发
- 一起talk C栗子吧(第七十三回:C语言实例--DIY pwd命令)
- 旋转数组的最小数字
- 单例模式
- android学习笔记——GridView控件(九宫格布局)
- POJ3579 二分
- STM32学习笔记(4):SysTick
- poj 1860-Currency Exchange(Bellman_Ford算法)
- [笔记] 大型网站技术架构——核心原理与案例分析 [一]
- 斐波那契数列
- android学习笔记——ImageSwitcher控件(图片切换器)