当前位置:网站首页>LeetCode162-寻找峰值-二分-数组
LeetCode162-寻找峰值-二分-数组
2022-04-23 14:48:00 【李烦烦搞快点】
Note:
二分,每次判断一下子是不是峰值,峰值在哪边就好了
不过我们这里条件和变动要统一好,如果我们打算往右边找,就要让他和前一个去比,这样就不会越界
代码如下:
class Solution {
public:
int findPeakElement(vector<int>& nums) {
int l = 0, r = nums.size() - 1;
while(l < r){
int mid = l + r + 1 >> 1;
if(nums[mid] > nums[mid - 1]) l = mid;
else r = mid - 1;
}
return r;
}
};
版权声明
本文为[李烦烦搞快点]所创,转载请带上原文链接,感谢
https://blog.csdn.net/Mr_Ghost812/article/details/124354942
边栏推荐
- 自动化的艺术
- 八路抢答器系统51单片机设计【附Proteus仿真、C程序、原理图及PCB文件、元器件清单和论文等】
- Bingbing learning notes: take you step by step to realize the sequence table
- 【STC8G2K64S4】比较器介绍以及比较器掉电检测示例程序
- go基础 反射
- 成都控制板设计提供_算是详细了_单片机程序头文件的定义、编写及引用介绍
- Svn detailed use tutorial
- What is the main purpose of PCIe X1 slot?
- Want to be an architect? Tamping the foundation is the most important
- Matrix exchange row and column
猜你喜欢
在游戏世界组建一支AI团队,超参数的多智能体「大乱斗」开赛
电容
Swift protocol Association object resource name management multithreading GCD delay once
[stc8g2k64s4] introduction of comparator and sample program of comparator power down detection
MySQL error packet out of order
Mq-2 and DS18B20 fire temperature smoke alarm system design, 51 single chip microcomputer, with simulation, C code, schematic diagram, PCB, etc
详解TCP的三次握手
成都控制板设计提供_算是详细了_单片机程序头文件的定义、编写及引用介绍
qt之.pro文件详解
想要成为架构师?夯实基础最重要
随机推荐
51 Single Chip Microcomputer Design of traffic light system (with Proteus simulation, C program, schematic diagram, PCB, thesis and other complete data)
《JVM系列》 第七章 -- 字节码执行引擎
I/O复用的高级应用之一:非阻塞 connect———使用 select 实现(也可以用 poll 实现)
AT89C51 MCU digital voltmeter development, measuring range 0 ~ 5V, proteus simulation, schematic diagram, PCB and C program, etc
select 同时接收普通数据 和 带外数据
GIS数据处理-cesium中模型位置设置
科技的成就(二十一)
A good tool: aardio
epoll 的 ET,LT工作模式———实例程序
Vscode Chinese plug-in doesn't work. Problem solving
Ali developed three sides, and the interviewer's set of combined punches made me confused on the spot
剑指 Offer II 019. 最多删除一个字符得到回文(简单)
[detailed explanation of factory mode] factory method mode
如何打开Win10启动文件夹?
直流可调稳压电源的Proteus仿真设计(附仿真+论文等资料)
SHT11传感器的温度湿度监控报警系统单片机Proteus设计(附仿真+论文+程序等)
ASEMI整流模块MDQ100-16在智能开关电源中的作用
自动化的艺术
想要成为架构师?夯实基础最重要
epoll 的EPOLLONESHOT 事件———实例程序