剑指offer题六
来源:互联网 发布:淘宝免费充话费 编辑:程序博客网 时间:2024/06/07 08:51
//把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转。
//输入一个非递减排序的数组的一个旋转,输出旋转数组的最小元素。
//例如数组{3,4,5,1,2}为{1,2,3,4,5}的一个旋转,该数组的最小值为1。
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] array = new int[n];
for(int i = 0;i<n;i++){
array[i] = sc.nextInt();
}
System.out.println(minNumberInRotateArray(array));
}
public static int minNumberInRotateArray(int [] array) {
if(array.length == 0){
return 0;
}
for(int i = 0;i<array.length-1;i++){
if(array[i]>array[i+1]){
return array[i+1];
}
}
return array[0];
}
//输入一个非递减排序的数组的一个旋转,输出旋转数组的最小元素。
//例如数组{3,4,5,1,2}为{1,2,3,4,5}的一个旋转,该数组的最小值为1。
//NOTE:给出的所有元素都大于0,若数组大小为0,请返回0。
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] array = new int[n];
for(int i = 0;i<n;i++){
array[i] = sc.nextInt();
}
System.out.println(minNumberInRotateArray(array));
}
public static int minNumberInRotateArray(int [] array) {
if(array.length == 0){
return 0;
}
for(int i = 0;i<array.length-1;i++){
if(array[i]>array[i+1]){
return array[i+1];
}
}
return array[0];
}
0 0
- 剑指offer题六
- 剑指offer(题六)
- 剑指offer 六
- 剑指offer(六)
- 剑指offer(六)之变态跳台阶
- 剑指offer之编程(六)
- 剑指offer经典编程(六)
- 剑指offer 练习六(Java版)
- 剑指Offer编程整理(六)
- 剑指Offer算法实现之六:重建二叉树
- 剑指offer系列之六:旋转数组的最小值
- 剑指Offer----面试题六:重建二叉树
- (六)剑指offer之旋转数组的最小数字
- 剑指Offer题目JAVA版思路与代码(六)
- 《剑指Offer》面试题六之重建二叉树
- 剑指offer(六)旋转数组的最小数字
- 剑指offer之六---菲波那切数列
- 剑指offer第一题
- ubuntu16.04空间扩容
- 剑指offer题七
- 设置ODBC数据源时候更改默认数据库时没有新建的数据库
- Leetcode :palindrome partitioning(c++)
- Spring概念
- 剑指offer题六
- 蓝桥杯 分巧克力(二分)
- MySQL基本操作
- 闭包与匿名函数
- Colliders CodeForces
- Groovy 里常用的异步操作方式
- 《Training:Supporting Different Platform Versions》
- fiddle,修改请求数据
- 腾讯笔试编程题