当前位置:网站首页>Leetcode the smallest number of the rotation array of the offer of the sword (11)
Leetcode the smallest number of the rotation array of the offer of the sword (11)
2022-07-03 14:59:00 【& eternal Galaxy &】
Title Description
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.
source : Power button (LeetCode)
link :https://leetcode-cn.com/problems/xuan-zhuan-shu-zu-de-zui-xiao-shu-zi-lcof
Copyright belongs to the network . For commercial reprint, please contact the official authority , Non-commercial reprint please indicate the source .
Example 1:
Input :[3,4,5,1,2] Output :1
Example 2:
Input :[2,2,2,0,1] Output :0
Coding ideas :
Two points search
Python3 Realization
class Solution:
def minArray(self, numbers: List[int]) -> int:
low = 0
high = len(numbers) - 1
while low < high:
mid = low + (high - low) // 2
if numbers[mid] > numbers[high]:
low = mid + 1
elif numbers[mid] < numbers[high]:
high = mid
else:
high -= 1
return numbers[low]C++ Realization
class Solution {
public:
int minArray(vector<int>& numbers) {
int low = 0;
int high = numbers.size() - 1;
while(low < high){
int mid = static_cast<int>(low + (high - low) / 2);
if(numbers[mid] > numbers[high]){
low = mid + 1;
}else if(numbers[mid] < numbers[high]){
high = mid;
}else{
high -= 1;
}
}
return numbers[low];
}
};边栏推荐
- 创业团队如何落地敏捷测试,提升质量效能?丨声网开发者创业讲堂 Vol.03
- Dllexport and dllimport
- Global and Chinese markets for ionization equipment 2022-2028: Research Report on technology, participants, trends, market size and share
- NOI OPENJUDGE 1.5(23)
- [graphics] hair simulation in tressfx
- [combinatorics] permutation and combination (set combination, one-to-one correspondence model analysis example)
- Amazon, express, lazada, shopee, eBay, wish, Wal Mart, Alibaba international, meikeduo and other cross-border e-commerce platforms evaluate how Ziyang account can seize traffic by using products in th
- [engine development] rendering architecture and advanced graphics programming
- Global and Chinese markets for flexible chips 2022-2028: Research Report on technology, participants, trends, market size and share
- [ue4] HISM large scale vegetation rendering solution
猜你喜欢

什么是one-hot encoding?Pytorch中,将label变成one hot编码的两种方式

On MEM series functions of C language

Série yolov5 (i) - - netron, un outil de visualisation de réseau

Solve the problem that PR cannot be installed on win10 system. Pr2021 version -premiere Pro 2021 official Chinese version installation tutorial
![[graphics] hair simulation in tressfx](/img/41/cef55811463d3a25a29ddab5278af0.jpg)
[graphics] hair simulation in tressfx

Byte practice surface longitude

Yolov5 series (I) -- network visualization tool netron
![[graphics] real shading in Unreal Engine 4](/img/8d/53775c7570c5578f4fe985592bb305.jpg)
[graphics] real shading in Unreal Engine 4
![[ue4] Niagara's indirect draw](/img/8a/576022b5d19e1d6422ff0135c50c93.jpg)
[ue4] Niagara's indirect draw

Devaxpress: range selection control rangecontrol uses
随机推荐
Global and Chinese markets of AC electromechanical relays 2022-2028: Research Report on technology, participants, trends, market size and share
Yolov5进阶之八 高低版本格式转换问题
Qt development - scrolling digital selector commonly used in embedded system
Adobe Premiere Pro 15.4 has been released. It natively supports Apple M1 and adds the function of speech to text
ASTC texture compression (adaptive scalable texture compression)
QT - draw something else
Global and Chinese market of transfer case 2022-2028: Research Report on technology, participants, trends, market size and share
Several sentences extracted from the book "leather bag"
4-20-4-23 concurrent server, TCP state transition;
[combinatorics] permutation and combination (set combination, one-to-one correspondence model analysis example)
QT program font becomes larger on computers with different resolutions, overflowing controls
Zzuli: cumulative sum of 1050 factorials
B2020 points candy
mmdetection 学习率与batch_size关系
5.4-5.5
什么是Label encoding?one-hot encoding ,label encoding两种编码该如何区分和使用?
【Transform】【NLP】首次提出Transformer,Google Brain团队2017年论文《Attention is all you need》
cpu飙升排查方法
NOI OPENJUDGE 1.3(06)
Piwigo 2.7.1 sqli learning