当前位置:网站首页>[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];
}
}
边栏推荐
- Research Report on micro vacuum pump industry - market status analysis and development prospect prediction
- Gbase8s database type
- China plastic box market trend report, technological innovation and market forecast
- SQL必需掌握的100个重要知识点:管理事务处理
- PIP version update timeout - download using domestic image
- Introduction to victoriametrics
- 如何防止你的 jar 被反编译?
- D4:非成对图像去雾,基于密度与深度分解的自增强方法(CVPR 2022)
- Destroy in beforedestroy invalid value in localstorage
- *C语言期末课程设计*——通讯录管理系统(完整项目+源代码+详细注释)
猜你喜欢

Daily book - low code you must understand in the era of digital transformation

关于测试用例
![[Yu Yue education] reference materials of analog electronic technology of Nanjing Institute of information technology](/img/2f/bb99836bb3ad725483f30531ff4d53.jpg)
[Yu Yue education] reference materials of analog electronic technology of Nanjing Institute of information technology

kubernetes资源对象介绍及常用命令(四)

Secondary development of ANSYS APDL: post processing uses command flow to analyze the result file

pip安装whl文件报错:ERROR: ... is not a supported wheel on this platform

D4: unpaired image defogging, self enhancement method based on density and depth decomposition (CVPR 2022)

sql service 截取字符串

Evolution of messaging and streaming systems under the native tide of open source cloud

Daily book -- analyze the pain points of software automation from simple to deep
随机推荐
SQL必需掌握的100个重要知识点:使用游标
分享一下如何制作专业的手绘电子地图
Etcd raft protocol
The web version of xshell supports FTP connection and SFTP connection [detailed tutorial] continued from the previous article
beginning
pip安裝whl文件報錯:ERROR: ... is not a supported wheel on this platform
Research Report on minimally invasive medical robot industry - market status analysis and development prospect prediction
Blue Bridge Cup Eliminate last one (bit operation, code completion)
MySQL learning record (3)
pyqt圖片解碼 編碼後加載圖片
读博士吧,研究奶牛的那种!鲁汶大学 Livestock Technology 组博士招生,牛奶质量监测...
CVPR论文解读 | 弱监督的高保真服饰模特生成
SQL必需掌握的100个重要知识点:管理事务处理
Research Report on market supply and demand and strategy of microplate instrument industry in China
Secondary development of ANSYS APDL: post processing uses command flow to analyze the result file
Micro SD Card Industry Research Report - market status analysis and development prospect forecast
Image segmentation using pixellib
[CV] Wu Enda machine learning course notes | Chapter 12
What "real skills" should a million year old cloud native developer master? Alibaba, Tencent, meituan and byte decrypt together
MySQL learning record (4)