旋转数组的最小数字
来源:互联网 发布:两个矩阵的协方差公式 编辑:程序博客网 时间:2024/05/16 06:27
把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转。
输入一个非递减排序的数组的一个旋转,输出旋转数组的最小元素。
例如数组{3,4,5,1,2}为{1,2,3,4,5}的一个旋转,该数组的最小值为1。
NOTE:给出的所有元素都大于0,若数组大小为0,请返回0。
备注:这是二分查找的变形应用。
请注意下面代码只是笔记没有参考价值。
public class Solution10 { public static int minNumberInRotateArray(int [] array) { System.out.println("数组长度:"+array.length); System.out.println("打印输入数组:"); for (int k=0;k<array.length;k++){ System.out.print("\t"+array[k]); } if (array.length == 0){ return 0; } if (array.length == 1 ){ //return array[0]; System.out.println(array[0]); } int mid = (int)Math.floor(array.length/2);//有小数都舍去,double转int--- mid=2 array[2]=5 System.out.println(); System.out.println("翻转后的数组:"); for (int j=3;j<5;j++){ System.out.print("\t"+array[j]); } for (int i=0;i<=2;i++){ System.out.print("\t"+array[i]); } return 0; } public static void main(String args[]){ int[] a = {3,4,5,1,2}; minNumberInRotateArray(a); }}
0 0
- 旋转数组的最小数字
- 旋转数组的最小数字
- 旋转数组的最小数字
- 旋转数组的最小数字
- 旋转数组的最小数字
- 旋转数组的最小数字
- 旋转数组的最小数字
- 旋转数组的最小数字
- 旋转数组的最小数字
- 旋转数组的最小数字
- 旋转数组的最小数字
- 旋转数组的最小数字
- 旋转数组的最小数字
- 旋转数组的最小数字
- 旋转数组的最小数字
- 旋转数组的最小数字
- 旋转数组的最小数字
- 旋转数组的最小数字
- MySQL(五)--数据类型
- 还是01串
- http://codeforces.com/problemset/problem/712/C
- 选择排序
- hdu1285 确定比赛名次(拓扑排序)
- 旋转数组的最小数字
- PAT_A 1036. Boys vs Girls (25)
- Java虚拟机(HotSpot)对象
- 良心推荐十款堪称神器的软件
- Accelerated C++<4-4>
- Vue.js之devtools
- 19. 标准函数库
- 信息熵
- 【java】简单的双人五子棋