当前位置:网站首页>Minimum number to rotate array
Minimum number to rotate array
2022-07-30 00:18:00 【Ryuzaki Liuhe】
题目:
把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转.
给你一个可能存在 重复 元素值的数组 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 {
//This problem is similar to find the minimum known as rotating point,Direct sequencing of courseokBut high time complexity will
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];
}
}
边栏推荐
- Unity Addressables
- How do we-media people create explosive articles?These 3 types of articles are most likely to explode
- Expansion of Parallel I/O Port in Single Chip Microcomputer Development
- The strongest JVM in the whole network is coming!(Extreme Collector's Edition)
- Internship in a group
- 利用热点事件来创作软文的3大技巧?自媒体人必看
- Google Chrome (google) is set to translate Chinese, the translation option does not take effect or the translation option does not pop up
- CNN的粗浅理解
- X64 mfc140u.dll文件缺失->应用程序无法正常启动(0xc000007b)解决方法
- 旋转数组的最小数字
猜你喜欢
NumPy(二)
[Best training DAY16] KC's Can [Dynamic programming]
低压差线性稳压器MPQ2013A-AEC1品牌MPS国产替代
vim相关介绍(二)
[Cloud native Kubernetes] Build a Kubernetes cluster in binary (middle) - deploy node nodes
Vmtouch - under Linux file cache management artifact
关于 byte 的范围
"The lighthouse factory" of China path: smart roll out from point to surface
He cell separation technology 丨 basic primary cell separation methods and materials
Worthington解离酶:中性蛋白酶(分散酶)详情解析
随机推荐
QTableWidget usage example
EA & UML Sun Arch - State Diagram :: Redraw Button State Diagram
绘制几何图形
抖音短视频流量获取攻略,掌握好这些一定可以出爆款
rk-boot framework combat (1)
窗口函数笔记
字符串替换空格
Google Chrome (google) is set to translate Chinese, the translation option does not take effect or the translation option does not pop up
I.MX6U-驱动开发-3-新字符驱动
Types and check set (set), study T treasure code
He used to cells harvested trypsin & release procedure
2022/7/29 Exam Summary
7.28
Replace the executable file glibc version of the one
【励志】科比精神
NumPy(一)
重写并自定义依赖的原生的Bean方法
【集训DAY16】KC‘s Can 【动态规划】
Graph Theory: Bipartite Graphs
定时器学习