剑指offer之旋转数组的最小数字
来源:互联网 发布:自导自演 周杰伦 知乎 编辑:程序博客网 时间:2024/06/05 00:08
题目:
把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转。 输入一个非递减排序的数组的一个旋转,输出旋转数组的最小元素。 例如数组{3,4,5,1,2}为{1,2,3,4,5}的一个旋转,该数组的最小值为1。 NOTE:给出的所
有元素都大于0,若数组大小为0,请返回0。
思路:
从后向前查找,当遇到前一位大于后一位时,停止查找,后一位即最小值。
代码:
class Solution {public: int minNumberInRotateArray(vector<int> rotateArray) { if(rotateArray.empty()) return 0; int len=rotateArray.size()-1; while(len-1>=0 && rotateArray[len-1]<=rotateArray[len]) len--; return rotateArray[len]; }};
阅读全文
0 0
- 剑指Offer之旋转数组的最小数字
- 《剑指Offer》之面试题旋转数组的最小数字
- 剑指Offer之 - 旋转数组的最小数字
- 剑指offer(九)之旋转数组的最小数字
- 剑指offer之旋转数组的最小数字
- (六)剑指offer之旋转数组的最小数字
- 剑指offer之旋转数组的最小数字
- 剑指offer之五---旋转数组的最小数字
- 剑指offer之旋转数组的最小数字
- 【剑指offer】旋转数组的最小数字
- 剑指offer--旋转数组的最小数字
- 剑指offer--旋转数组的最小数字
- 剑指offer:旋转数组的最小数字
- 《剑指offer》旋转数组的最小数字
- 剑指 offer:旋转数组的最小数字
- 剑指offer-旋转数组的最小数字
- 剑指offer 旋转数组的最小数字
- 【剑指offer】旋转数组的最小数字
- CentOS6.5安装memcached1.5.0
- SSL2669 2017年8月7日提高组T1 选数(dfs)
- 2017年8月8日提高组T1 作业
- 暑假集训每日总结 第N天 8.8
- Spinner 使用注意点
- 剑指offer之旋转数组的最小数字
- 二进制中有多少个1?
- HDU-4578:Transformation(有条件的延迟标记)
- 教育将是人工智能技术最佳的应用场景之一
- Numpy之tile用法
- indexedDB的基本使用
- Python利用Requests库写爬虫
- POJ
- OSI七层结构及TCP/IP五层结构