当前位置:网站首页>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];
}
};
边栏推荐
- Zzuli:1045 numerical statistics
- Global and Chinese markets for infrared solutions (for industrial, civil, national defense and security applications) 2022-2028: Research Report on technology, participants, trends, market size and sh
- Byte practice surface longitude
- Global and Chinese market of lighting control components 2022-2028: Research Report on technology, participants, trends, market size and share
- Remote server background hangs nohup
- NOI OPENJUDGE 1.6(09)
- C language DUP function
- [combinatorics] permutation and combination (set combination, one-to-one correspondence model analysis example)
- NOI OPENJUDGE 1.4(15)
- Piwigo 2.7.1 sqli learning
猜你喜欢
[ue4] geometry drawing pipeline
[graphics] real shading in Unreal Engine 4
PS tips - draw green earth with a brush
B2020 points candy
ASTC texture compression (adaptive scalable texture compression)
QT - draw something else
QT program font becomes larger on computers with different resolutions, overflowing controls
Rasterization: a practical implementation (2)
Pytorch深度学习和目标检测实战笔记
Detailed explanation of four modes of distributed transaction (Seata)
随机推荐
Zero copy underlying analysis
Zzuli:1049 square sum and cubic sum
On MEM series functions of C language
Mmdetection learning rate and batch_ Size relationship
[graphics] real shading in Unreal Engine 4
Global and Chinese market of solder bars 2022-2028: Research Report on technology, participants, trends, market size and share
Center and drag linked global and Chinese markets 2022-2028: Research Report on technology, participants, trends, market size and share
Tencent internship interview sorting
Awvs batch operation script
Zzuli:1052 sum of sequence 4
Global and Chinese market of marketing automation 2022-2028: Research Report on technology, participants, trends, market size and share
从书本《皮囊》摘录的几个句子
Pytoch deep learning and target detection practice notes
Zzuli:1059 highest score
Zzuli:1056 lucky numbers
Zzuli:1047 logarithmic table
. Net six design principles personal vernacular understanding, please correct if there is any error
C language memory function
dllexport和dllimport
Zzuli:1046 product of odd numbers