当前位置:网站首页>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];
}
};边栏推荐
- Time conversion ()
- C language dup2 function
- Global and Chinese market of solder bars 2022-2028: Research Report on technology, participants, trends, market size and share
- 什么是one-hot encoding?Pytorch中,将label变成one hot编码的两种方式
- Talking about part of data storage in C language
- 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
- Several sentences extracted from the book "leather bag"
- Yolov5进阶之八 高低版本格式转换问题
- How can entrepreneurial teams implement agile testing to improve quality and efficiency? Voice network developer entrepreneurship lecture Vol.03
- 7-1 positive integer a+b (15 points)
猜你喜欢

复合类型(自定义类型)
![[opengl] advanced chapter of texture - principle of flowmap](/img/dd/6208122fcc578caaf098301b185e03.jpg)
[opengl] advanced chapter of texture - principle of flowmap

C language to realize mine sweeping

Solve the problem that PR cannot be installed on win10 system. Pr2021 version -premiere Pro 2021 official Chinese version installation tutorial

分布式事务(Seata) 四大模式详解

远程服务器后台挂起 nohup
![[ue4] cascading shadow CSM](/img/83/f4dfda3bd5ba0172676c450ba7693b.jpg)
[ue4] cascading shadow CSM

5.2-5.3

Pytoch deep learning and target detection practice notes

Vs+qt multithreading implementation -- run and movetothread
随机推荐
1017 a divided by B (20 points)
Mmdetection learning rate and batch_ Size relationship
PS tips - draw green earth with a brush
Vs+qt multithreading implementation -- run and movetothread
Déformation de la chaîne bm83 de niuke (conversion de cas, inversion de chaîne, remplacement de chaîne)
Yolov5 advanced nine target tracking example 1
CentOS7部署哨兵Redis(带架构图,清晰易懂)
从书本《皮囊》摘录的几个句子
Optical cat super account password and broadband account password acquisition
Zzuli:1054 monkeys eat peaches
Zzuli: sum of 1051 square roots
4-24--4-28
Zzuli:1059 highest score
Qt development - scrolling digital selector commonly used in embedded system
[ue4] geometry drawing pipeline
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
[ue4] material and shader permutation
Web server code parsing - thread pool
Container of symfony
There are links in the linked list. Can you walk three steps faster or slower