当前位置:网站首页>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
边栏推荐
- UML project example -- UML diagram description of tiktok
- 1 - first knowledge of go language
- I/O复用的高级应用之一:非阻塞 connect———使用 select 实现(也可以用 poll 实现)
- ASEMI三相整流桥和单相整流桥的详细对比
- Detailed comparison between asemi three-phase rectifier bridge and single-phase rectifier bridge
- Using MATLAB programming to realize the steepest descent method to solve unconstrained optimization problems
- Epoll's et, lt working mode -- example program
- Electronic perpetual calendar of DS1302_ 51 single chip microcomputer, month, day, week, hour, minute and second, lunar calendar and temperature, with alarm clock and complete set of data
- 想要成为架构师?夯实基础最重要
- Bingbing learning notes: take you step by step to realize the sequence table
猜你喜欢

【工厂模式详解】工厂方法模式

你還不知道責任鏈模式的使用場景嗎?

Electronic scale weighing system design, hx711 pressure sensor, 51 single chip microcomputer (proteus simulation, C program, schematic diagram, thesis and other complete data)

编程哲学——自动加载、依赖注入与控制反转

qt之.pro文件详解

do(Local scope)、初始化器、内存冲突、Swift指针、inout、unsafepointer、unsafeBitCast、successor、

MCU function signal generator, output four kinds of waveforms, adjustable frequency, schematic diagram, simulation and C program

Matlab Simulink modeling and design of single-phase AC-AC frequency converter, with MATLAB simulation, PPT and papers

8.3 语言模型与数据集

线程同步、生命周期
随机推荐
I thought I could lie down and enter Huawei, but I was confused when I received JD / didi / iqiyi offers one after another
Pnpm installation and use
Chapter 7 of JVM series -- bytecode execution engine
Swift - Literal,字面量协议,基本数据类型、dictionary/array之间的转换
A blog allows you to learn how to write markdown on vscode
Mq-2 and DS18B20 fire temperature smoke alarm system design, 51 single chip microcomputer, with simulation, C code, schematic diagram, PCB, etc
select 同时接收普通数据 和 带外数据
Epolloneshot event of epoll -- instance program
Detailed explanation of C language P2 selection branch statement
Mds55-16-asemi rectifier module mds55-16
利用 MATLAB 编程实现最速下降法求解无约束最优化问题
多语言通信基础 06 go实现grpc的四种数据流模式实现
When splicing HQL, the new field does not appear in the construction method
Programming philosophy - automatic loading, dependency injection and control inversion
Find daffodils - for loop practice
GIS数据处理-cesium中模型位置设置
qt之.pro文件详解
OC 转 Swift 条件编译、标记、宏、 Log、 版本检测、过期提示
PCIe X1 插槽的主要用途是什么?
冰冰学习笔记:一步一步带你实现顺序表
