当前位置:网站首页>Leetcode (Sword finger offer) - 11. Minimum number of rotation array
Leetcode (Sword finger offer) - 11. Minimum number of rotation array
2022-07-24 03:48:00 【Sheep yard】
Topic link : Click to open the link
The main idea of the topic : A little
Their thinking

Related enterprises
- Bytes to beat
- Amazon (Amazon)
AC Code
- Java
// Solution (1)
class Solution {
public int minArray(int[] numbers) {
int min = Math.min(numbers[0], numbers[numbers.length - 1]);
for (int i = 1; i < numbers.length - 1; i++) {
if (numbers[i] >= numbers[i - 1] && numbers[i] > numbers[i + 1]) {
min = numbers[i + 1];
break;
} else if (numbers[i] < numbers[i - 1]) {
min = numbers[i];
break;
}
}
return min;
}
}
// Solution (2)
class Solution {
public int minArray(int[] numbers) {
int i = 0, j = numbers.length - 1;
while (i < j) {
int m = (i + j) / 2;
if (numbers[m] > numbers[j]) i = m + 1;
else if (numbers[m] < numbers[j]) j = m;
else {
int x = i;
for(int k = i + 1; k < j; k++) {
if(numbers[k] < numbers[x]) x = k;
}
return numbers[x];
}
}
return numbers[i];
}
}- C++
class Solution {
public:
int minArray(vector<int>& numbers) {
int i = 0, j = numbers.size() - 1;
while (i < j) {
int m = (i + j) / 2;
if (numbers[m] > numbers[j]) i = m + 1;
else if (numbers[m] < numbers[j]) j = m;
else {
int x = i;
for(int k = i + 1; k < j; k++) {
if(numbers[k] < numbers[x]) x = k;
}
return numbers[x];
}
}
return numbers[i];
}
};边栏推荐
- Master chip csu18m92 develops intelligent scale scheme
- MySql的DDL和DML和DQL的基本语法
- Pit encountered in project upgrading
- Developers share mindspire Lite experience, one click image segmentation
- Leetcode Hot 100 (topic 8) (232/88/451/offer10/offer22/344/)
- Matlab Simulink simulation of lithium iron phosphate battery
- PAT甲级 1040 Longest Symmetric String
- MySQL学习——MySQL软件的安装及环境配置(Windows)详细!
- Do you know how to do interface testing well?
- Experiment 6 MPEG
猜你喜欢

Qt ROS相关操作(运行终端指令、发布订阅自定义消息话题或服务、订阅图像并显示)

MySql的DDL和DML和DQL的基本语法

Sqlserver backup restore

MySQL cannot be accessed. Navicat prompt: is not allowed to connect to this MySQL server

CVE-2022-29464 WSO2文件上传漏洞

Leetcode-382. random nodes of linked list

Matlab sound signal processing frequency diagram signal filtering and playing sound

Worthington hydroxysteroid dehydrogenase technical description and determination scheme

08 reptile project

6-15 vulnerability exploitation SMB rce remote command execution
随机推荐
STL set容器
Idea failed to load resource: the server responded with a status of 404 (not found)
dynamixel舵机在ros下的workbnech使用
Cve-2022-29464 wso2 file upload vulnerability
MySQL learning - MySQL software installation and environment configuration (Windows) details!
Technical dry goods | evaluation index based on mindspire detailed perflexity language model
STL set容器
Basic syntax of MySQL DDL and DML and DQL
oh-my-zsh
[cloud native] get to know kubernetes quickly
PyTorch生态简介
Two stroke engine mean value model simulation
C language classic exercises (2) - "bubble sort"“
Configure IPv6 over IP manual tunnel using routing protocol
Advanced embedded application of uni app [day14]
SLAAC stateless address automatic configuration
Pit encountered in project upgrading
Worthington mammalian lactate dehydrogenase study -- Characteristics and determination scheme
The list should be quickly familiar with and supported by shengteng AI processor
Conteneur STL set