当前位置:网站首页>[jzof] 11 minimum number of rotation array
[jzof] 11 minimum number of rotation array
2022-07-23 13:19:00 【Sighed, angry】
describe :
There is a length of n Non descending array of , such as [1,2,3,4,5], Rotate it , That is, move the first elements of an array to the end of the array , Into a rotating array , For example, it became [3,4,5,1,2], perhaps [4,5,1,2,3] In this way . Excuse me, , Given such a rotation array , Find the minimum value in the array .
Data range :1≤n≤10000, The value of any element in the array : 0<=val≤10000;
requirement : Spatial complexity :O(1) , Time complexity :O(logn).

import java.util.ArrayList;
public class Solution {
public int minNumberInRotateArray(int [] array) {
// Judgment of special circumstances
if (array.length== 0) {
return 0;
}
// Left and right pointer i j
int i = 0, j = array.length - 1;
// loop
while (i < j) {
// Find the midpoint of the array m
int m = (i + j) / 2;
// m In the left sort array , Rotation point at [m+1, j] in
if (array[m] > array[j]) i = m + 1;
// m In the right sort array , Rotation point at [i, m] in
else if (array[m] < array[j]) j = m;
// Narrow down and continue to judge
else j--;
}
// Return to the rotation point
return array[i];
}
}
边栏推荐
- 数据进行脱敏
- 【JZOF】09用两个栈实现队列
- [ACTF2020 新生赛]BackupFile 1
- 【NOI模拟赛】不知是哪一道CF的论文题(概率期望,鞅的停时定理)
- 谈谈学习和工作——钱学森
- 记录一次爬虫题库
- When using fastjson to parse and assign JSON data, the order of JSON fields is inconsistent
- OpenCV图像处理(上)几何变换+形态学操作
- 第十一天笔记
- Software testing jobs saturated? Automated testing is a new generation of 'offer' skills
猜你喜欢

Beifu and C transmit real type through ads communication

Beifu PLC and C transmit bool type variables through ads communication

com.mysql.cj.jdbc.exceptions. MysqlDataTruncation: Data truncation: Truncated incorrect DOUBLE value:

图像处理 图像特征提取与描述

转行软件测试有学历要求吗?低于大专是真的没出路吗?

Software testing jobs saturated? Automated testing is a new generation of 'offer' skills

Opencv video operation

C语言-大端存储和小端存储

Beifu PLC and C transmit int type variables through ads communication

Opencv image processing (medium) image smoothing + histogram
随机推荐
Are there any academic requirements for career transfer software testing? Is there really no way out below junior college?
Successful joint commissioning of Vientiane Aoke and CoDeSys Technology
分类模型的评估
太空射击 Part 2-3: 子弹与敌人碰撞处理
Record a reptile question bank
How does redis implement persistence? Explain in detail the three triggering mechanisms of RDB and their advantages and disadvantages, and take you to quickly master RDB
Beifu PLC -- C ads communication reads variables in the form of notification
Communicate 11 tips for poor performance 
转行软件测试有学历要求吗?低于大专是真的没出路吗?
Beifu and C transmit real type through ads communication
【JZOF】09用两个栈实现队列
Signal integrity (SI) power integrity (PI) learning notes (XXXI) power distribution network (III)
基于redis+lua进行限流
CAN控制器的位同步过程
将集合使用流进行分页
The context of virtual memory technology (Part 1)
太空射击 Part 1: 玩家精灵和控制
OpenVPN deployment
Beifu PLC and C transmit bool array variables through ads communication
The unity model is displayed in front of the UI, and the UI behind it jitters