当前位置:网站首页>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];
}
}

边栏推荐
- 【集训DAY16】KC ‘ s Stars【dfs】
- Decision tree principle and code implementation
- Worthington酶促细胞收获&细胞粘附和收获
- Worthington's tried and tested cell isolation system protocols
- 4 hotspot inquiry networks necessary for new media operations
- Codeforces Round #805 (Div. 3) Summary
- Elephant Swap: Provide arbitrage space in the crypto market with ePLATO
- 循环神经网络(RNN)
- QTableWidget usage example
- Override and customize dependent native Bean methods
猜你喜欢
随机推荐
Worthington Enzymatic Cell Harvest & Cell Adhesion and Harvest
谷歌浏览器(google)设置翻译中文,翻译选项不生效或没有弹出翻译选项
外包干了五年,废了...
机器人的运动范围
【Incubator DAY18】Interesting exchange【Simulation】【Math】
Mysql internal and external connections
字符串替换空格
“ 我是一名阿里在职9年软件测试工程师,我的经历也许能帮到处于迷茫期的你 ”
Weekly recommended short video: What is R&D efficiency?It can achieve anti "involution"?
EA & UML Sun Arch - State Diagram :: Redraw Button State Diagram
rk-boot framework combat (1)
Go日志库——logrus
Worthington Optimized Technology: Cell Quantification
2022年ps应该选择哪个版本
18 Lectures on Disassembly of Multi-merchant Mall System Functions
Worthington弹性蛋白酶&透明质酸酶简介
Chinese semantic matching
Decision tree principle and code implementation
BEVDetNet: Bird's Eye View LiDAR Point Cloud based Real-time 3D Object Detection for Autonomous Drivi
1592. 重新排列单词间的空格








