当前位置:网站首页>旋转数组的最小数字
旋转数组的最小数字
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];
}
}
边栏推荐
- 机器人的运动范围
- what is a .pro file in qt
- Worthington Papain & Chymotrypsin & DNase I
- SQL Server、MySQL主从搭建,EF Core读写分离代码实现
- Mysql internal and external connections
- 头条号自媒体运营:如何在今日头条涨500+粉丝?
- Worthington经过使用测试的细胞分离系统方案
- Low dropout linear regulator MPQ2013A-AEC1 brand MPS domestic replacement
- “灯塔工厂”的中国路径:智造从点到面铺开
- Worthington's tried and tested cell isolation system protocols
猜你喜欢
Elephant Swap: Provide arbitrage space in the crypto market with ePLATO
基于TNEWS‘ 今日头条中文新闻(短文本)分类
Worthington用于细胞收获的胰蛋白酶&细胞释放程序
Chinese semantic matching
CesiumJS ^ source read [0] 2022 - article directory and source engineering structure
Worthington解离酶:胶原酶及四个基本概况
“ 我是一名阿里在职9年软件测试工程师,我的经历也许能帮到处于迷茫期的你 ”
绘制几何图形
利用热点事件来创作软文的3大技巧?自媒体人必看
综合练习——三子棋小游戏
随机推荐
Mysql internal and external connections
BEVDetNet:Bird‘s Eye View LiDAR Point Cloud based Real-time 3D Object Detection for Autonomous Drivi
C陷阱与缺陷 第4章 链接 4.1 什么是链接器
【集训DAY18】Welcome J and Z 【动态规划】
Codeforces Round #805 (Div. 3) Summary
Adaptive feature fusion pyramid network for multi-classes agriculturalpest detection
BEVDetNet: Bird's Eye View LiDAR Point Cloud based Real-time 3D Object Detection for Autonomous Drivi
Toutiao We-Media Operation: How to Gain 500+ Fans in Toutiao Today?
MySQL 用 BETWEEN AND 日期查询包含范围边界
At the age of 29, I was fired from a functional test. Can't find a job after 2 months of interviews?
一文解答web性能优化
2022年企业直播行业发展洞察
Introduction to Worthington Elastase & Hyaluronidase
go语言序列化和反序列化及序列化后的json为空和json的key值大写如何改为小写问题
YoloV5数据集自动划分训练集、验证集、测试集
Types and check set (set), study T treasure code
EA&UML日拱一卒-多任务编程超入门-(9)线程同步
消息中间件解析 | 如何正确理解软件应用系统中关于系统通信的那些事?
Override and customize dependent native Bean methods
Worthington Papain & Chymotrypsin & DNase I