当前位置:网站首页>旋转数组的最小数字
旋转数组的最小数字
2022-07-30 00:09:00 【龙崎流河】
题目:
把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转。
给你一个可能存在 重复 元素值的数组 numbers ,它原来是一个升序排列的数组,并按上述情形进行了一次旋转。请返回旋转数组的最小元素。例如,数组 [3,4,5,1,2] 为 [1,2,3,4,5] 的一次旋转,该数组的最小值为 1。
注意,数组 [a[0], a[1], a[2], …, a[n-1]] 旋转一次 的结果为数组 [a[n-1], a[0], a[1], a[2], …, a[n-2]] 。
分析:
代码:
public class MinArray {
//这道题就类似于找最小值也就是所谓的旋转点,直接排序找当然ok但时间复杂度会高
public int minArray(int[] numbers) {
int l = 0;
int r = numbers.length-1;
while ( l < r){
if (numbers[l] < numbers[r]){
return numbers[l];
}
int mid = (l+r)/2;
if (numbers[mid]>numbers[l]){
l = mid + 1;
}else if(numbers[mid]<numbers[l]){
r = mid;
}else {
l++;
}
}
return numbers[l];
}
}

边栏推荐
- KDE Frameworks 5.20.0: Plasma welcomes many improvements
- 基于TNEWS‘ 今日头条中文新闻(短文本)分类
- Worthington Papain & Chymotrypsin & DNase I
- Worthington弹性蛋白酶&透明质酸酶简介
- Worthington Dissociation Enzymes: Trypsin and Frequently Asked Questions
- Getting Started with Sentinel
- Some personal understandings about MySQL indexes (partially refer to MySQL45 lectures)
- 4 hotspot inquiry networks necessary for new media operations
- Expansion of Parallel I/O Port in Single Chip Microcomputer Development
- Unity Addressables
猜你喜欢
随机推荐
KDE Frameworks 5.20.0:Plasma迎来诸多改进
随便记记第二周
Worthington酶促细胞收获&细胞粘附和收获
2022/7/29 Exam Summary
Worthington Dissociation Enzymes: Collagenase and Four Basic Profiles
ZLMediaKit源码分析 - NotifyCenter
Some personal understandings about MySQL indexes (partially refer to MySQL45 lectures)
2022/7/29 考试总结
opencv基本图像的滤波
【分层强化学习】HAC源码解读
C陷阱与缺陷 第5章 库函数 5.3 缓冲输出与内存分配
Codeforces Round #805 (Div. 3)总结
I.MX6U-驱动开发-3-新字符驱动
学会使用MySQL的Explain执行计划,SQL性能调优从此不再困难
Minesweeper game in c language
NumPy(一)
KDE Frameworks 5.20.0: Plasma welcomes many improvements
“ 我是一名阿里在职9年软件测试工程师,我的经历也许能帮到处于迷茫期的你 ”
PyTorch笔记 - Attention Is All You Need (1)
关于MySQL索引的一些个人理解(部分参考MySQL45讲)








