当前位置:网站首页>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];
}
};边栏推荐
- Niuke bm83 string deformation (case conversion, string inversion, string replacement)
- [opengl] bone animation blending effect
- 什么是Label encoding?one-hot encoding ,label encoding两种编码该如何区分和使用?
- Zzuli:1056 lucky numbers
- dllexport和dllimport
- Global and Chinese market of transfer case 2022-2028: Research Report on technology, participants, trends, market size and share
- Centos7 deployment sentry redis (with architecture diagram, clear and easy to understand)
- Zzuli:1044 failure rate
- 【微信小程序】WXSS 模板样式
- How can entrepreneurial teams implement agile testing to improve quality and efficiency? Voice network developer entrepreneurship lecture Vol.03
猜你喜欢

4-20-4-23 concurrent server, TCP state transition;

Talking about part of data storage in C language

Dllexport and dllimport

ASTC texture compression (adaptive scalable texture compression)

cpu飙升排查方法

CentOS7部署哨兵Redis(带架构图,清晰易懂)

How to color ordinary landscape photos, PS tutorial

Bucket sorting in C language

【注意力机制】【首篇ViT】DETR,End-to-End Object Detection with Transformers网络的主要组成是CNN和Transformer

4-33--4-35
随机推荐
Byte practice surface longitude
[combinatorics] permutation and combination (set combination, one-to-one correspondence model analysis example)
Global and Chinese markets for transparent OLED displays 2022-2028: Research Report on technology, participants, trends, market size and share
Tensor 省略号(三个点)切片
1017 a divided by B (20 points)
[opengl] pre bake using computational shaders
How to color ordinary landscape photos, PS tutorial
Center and drag linked global and Chinese markets 2022-2028: Research Report on technology, participants, trends, market size and share
406. Reconstruct the queue according to height
4-20-4-23 concurrent server, TCP state transition;
链表有环,快慢指针走3步可以吗
PHP GD image upload bypass
分布式事务(Seata) 四大模式详解
[graphics] efficient target deformation animation based on OpenGL es 3.0
Troubleshooting method of CPU surge
PS tips - draw green earth with a brush
Zzuli:1057 prime number determination
Zzuli: sum of 1051 square roots
C # realizes the login interface, and the password asterisk is displayed (hide the input password)
Zzuli:1045 numerical statistics