当前位置:网站首页>[leetcode] sword finger offer 11 Rotate the minimum number of the array
[leetcode] sword finger offer 11 Rotate the minimum number of the array
2022-07-02 21:52:00 【Chinese fir sauce_】
subject :
The finger of the sword Offer 11. Minimum number of rotation array
Move the first elements of an array to the end of the array , We call it rotation of arrays .
Give you a chance to exist repeat An array of element values numbers , It turns out to be an ascending array , And a rotation is carried out according to the above situation . Please return the smallest element of the rotation array . for example , Array [3,4,5,1,2] by [1,2,3,4,5] A rotation of , The minimum value of the array is 1.
Example 1:
Input :[3,4,5,1,2]
Output :1
Example 2:
Input :[2,2,2,0,1]
Output :0
Dichotomy :
class Solution {
public int minArray(int[] numbers) {
int l = 0,r = numbers.length - 1;
while(l < r) {
int mid = (l + r) / 2;
// If the one on the right is larger than the one in the middle , Then the one on the right is an ordered array , Then narrow the scope , Don't look at the one on the right
if(numbers[r] > numbers[mid]){
r = mid;
}
// If the one on the right is smaller than the one in the middle , Then the left is an ordered array , Then narrow the scope , Don't look at the one on the left
else if(numbers[r] < numbers[mid]) l = mid + 1;
// duplicate removal
else r--;
}
return numbers[r];
}
}
边栏推荐
- 基本IO接口技术——微机第七章笔记
- [C language] [sword finger offer article] - replace spaces
- Daily book CSO advanced road first exposed
- Image segmentation using pixellib
- Free open source web version of xshell [congratulations on a happy new year]
- Gbase 8s database basic syntax
- 【零基础一】Navicat下载链接
- 加了定位的文字如何水平垂直居中
- China plastic bottle and container market trend report, technological innovation and market forecast
- Blue Bridge Cup Winter vacation homework (DFS backtracking + pruning)
猜你喜欢

treevalue——Master Nested Data Like Tensor

读博士吧,研究奶牛的那种!鲁汶大学 Livestock Technology 组博士招生,牛奶质量监测...

VictoriaMetrics 简介

Cardinality sorting (detailed illustration)

MySQL learning record (2)

Basic IO interface technology - microcomputer Chapter 7 Notes

Technical solution of vision and manipulator calibration system

tinymce可视化编辑器增加百度地图插件

How to write a good program when a big book speaks every day?

Read a doctor, the kind that studies cows! Dr. enrollment of livestock technology group of Leuven University, milk quality monitoring
随机推荐
China plastic box market trend report, technological innovation and market forecast
It is said that this year gold three silver four has become gold one silver two..
Daily book CSO advanced road first exposed
MySQL inserts Chinese data and reports an error. Set the default collation
图像基础概念与YUV/RGB深入理解
pyqt圖片解碼 編碼後加載圖片
【剑指 Offer】57. 和为s的两个数字
Gbase 8s database basic syntax
The web version of xshell supports FTP connection and SFTP connection [detailed tutorial] continued from the previous article
Chargement de l'image pyqt après décodage et codage de l'image
TinyMCE visual editor adds Baidu map plug-in
Secondary development of ANSYS APDL: post processing uses command flow to analyze the result file
攻防世界pwn题:Recho
GEE:(二)对影像进行重采样
暑期第一周总结
SQL必需掌握的100个重要知识点:使用游标
SQL必需掌握的100个重要知识点:管理事务处理
Evolution of messaging and streaming systems under the native tide of open source cloud
《ActBERT》百度&悉尼科技大学提出ActBERT,学习全局局部视频文本表示,在五个视频-文本任务中有效!
How to write a good program when a big book speaks every day?