当前位置:网站首页>[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 minimally invasive medical robot industry - market status analysis and development prospect prediction
- Pip install whl file Error: Error: … Ce n'est pas une roue supportée sur cette plateforme
- Pyqt picture decodes and encodes and loads pictures
- Research Report on micro vacuum pump industry - market status analysis and development prospect prediction
- The neo4j skill tree was officially released to help you easily master the neo4j map database
- MySQL learning record (3)
- The failure rate is as high as 80%. What should we do about digital transformation?
- MySQL learning record (5)
- The book "new programmer 002" is officially on the market! From "new database era" to "software defined car"
- 发现你看不到的物体!南开&武大&ETH提出用于伪装目标检测SINet,代码已开源!...
猜你喜欢
Oriental Aesthetics and software design
基本IO接口技术——微机第七章笔记
How to prevent your jar from being decompiled?
D4:非成对图像去雾,基于密度与深度分解的自增强方法(CVPR 2022)
Interpretation of CVPR paper | generation of high fidelity fashion models with weak supervision
Cardinality sorting (detailed illustration)
MySQL learning record (7)
The book "new programmer 002" is officially on the market! From "new database era" to "software defined car"
Basic knowledge of tree and binary tree (detailed illustration)
[shutter] shutter page Jump (route | navigator | page close)
随机推荐
SQL必需掌握的100个重要知识点:使用游标
[shutter] shutter layout component (opacity component | clipprect component | padding component)
情感计算与理解研究发展概述
Micro SD Card Industry Research Report - market status analysis and development prospect forecast
Market trend report, technical dynamic innovation and market forecast of China's low gloss instrument
【零基础一】Navicat下载链接
20220702-程序员如何构建知识体系?
VictoriaMetrics 简介
Construction and maintenance of business websites [9]
The source code of the daily book analyzes the design idea of Flink and solves the problems in Flink
Pip install whl file Error: Error: … Ce n'est pas une roue supportée sur cette plateforme
It is said that this year gold three silver four has become gold one silver two..
技术人创业:失败不是成功,但反思是
【剑指 Offer】57. 和为s的两个数字
Analysis of neural network
From "bronze" to "King", there are three secrets of enterprise digitalization
Etcd Raft 协议
一周生活
LandingSite eBand B1冒烟测试用例
Find objects you can't see! Nankai & Wuhan University & eth proposed sinet for camouflage target detection, and the code has been open source