剑指offer-10 旋转数组
来源:互联网 发布:数码宝贝网络侦探续作 编辑:程序博客网 时间:2024/06/03 14:16
题目描述:把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转。 输入一个非递减排序的数组的一个旋转,输出旋转数组的最小元素。例如数组{3,4,5,1,2}为{1,2,3,4,5}的一个旋转,该数组的最小值为1。 NOTE:给出的所有元素都大于0,若数组大小为0,请返回0。
思路:
import java.util.ArrayList;
public class Solution {
public int minNumberInRotateArray(int [] array) {
if (array.length == 0){
return 0;
}
int low = 0;
int high = array.length-1;
while( low < high){
int mid = low + (high - low)/2;
if(array[mid] > array[high]){
low = mid + 1 ;
}else if(array[mid] == array[high]){
high = high -1;
//low = low + 1;
}else{
high = mid;
}
}
return array[low];
}
}
- 剑指offer-10 旋转数组
- 剑指offer-旋转数组
- 剑指offer 2.4 旋转数组
- 剑指offer -- 旋转数组最小值
- 【剑指offer】旋转数组的最小值
- 【剑指offer】旋转数组的最小数字
- 剑指offer面试题8--数组旋转
- 剑指offer--旋转数组的最小数字
- 剑指offer--旋转数组的最小数字
- 剑指Offer旋转数组中的最小数字
- 剑指offer:旋转数组的最小数字
- 《剑指offer》旋转数组的最小数字
- 剑指 offer:旋转数组的最小数字
- 剑指offer之旋转数组中的最小值
- 剑指offer-旋转数组的最小数字
- 剑指offer 旋转数组的最小数字
- 【剑指offer】旋转数组的最小数字
- 剑指offer 旋转数组的最小数字
- std::stringstream 用法
- 《将博客搬至CSDN》
- 让input只能输入数字
- 跨越问题
- z-index在css中的意思
- 剑指offer-10 旋转数组
- js的作用域问题及简单练习
- 项目中动态修改加载环境配置的几种方式
- Hyperledger fabric 源码分析之 peer 服务启动过程
- 兼容性问题小总结
- linux 下关于Python 调用shell命令的方式
- RabbitMQ之队列
- 随笔,jq children应用,,,获取域名,list应用比较广泛
- es6 基础总结