当前位置:网站首页>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 MCU + LCD12864 LCD Tetris game, proteus simulation, ad schematic diagram, code, thesis, etc
- Multisim Simulation Design of DC adjustable regulated power supply of LM317 (with simulation + paper + reference)
- Swift - Literal,字面量协议,基本数据类型、dictionary/array之间的转换
- [servlet] detailed explanation of servlet (use + principle)
- A good tool: aardio
- Introduction to Arduino for esp8266 serial port function
- 金九银十,入职字节跳动那一天,我哭了(蘑菇街被裁,奋战7个月拿下offer)
- 基于单片机的DS18B20的数字温度监控报警系统设计【LCD1602显示+Proteus仿真+C程序+论文+按键设置等】
- 【NLP】HMM隐马尔可夫+维特比分词
- GIS数据处理-cesium中模型位置设置
猜你喜欢
ArrayList collection basic usage
Detailed comparison between asemi three-phase rectifier bridge and single-phase rectifier bridge
抑郁症治疗的进展
The art of automation
Role of asemi rectifier module mdq100-16 in intelligent switching power supply
PWM speed regulation control system of DC motor based on 51 single chip microcomputer (with complete set of data such as Proteus simulation + C program)
[NLP] HMM hidden Markov + Viterbi word segmentation
DVWA之暴力破解(Brute Force)Low-->high
Detailed explanation of C language knowledge points -- first knowledge of C language [1]
Chapter 7 of JVM series -- bytecode execution engine
随机推荐
Role of asemi rectifier module mdq100-16 in intelligent switching power supply
Raised exception class eaccexviolation with 'access violation at address 45efd5 in module error
利用 MATLAB 编程实现最速下降法求解无约束最优化问题
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
SQLSERVER事物与锁的问题
Contraction mapping theorem
拼接hql时,新增字段没有出现在构造方法中
成都控制板设计提供_算是详细了_单片机程序头文件的定义、编写及引用介绍
Swift Protocol 关联对象 资源名称管理 多线程GCD 延迟 once
Matlab Simulink modeling and design of single-phase AC-AC frequency converter, with MATLAB simulation, PPT and papers
First acquaintance with STL
【Servlet】Servlet 详解(使用+原理)
raised exception class EAccexxViolation with ‘Access violation at address 45EFD5 in module 出错
Swift:Entry of program、Swift调用OC、@_silgen_name 、 OC 调用Swift、dynamic、String、Substring
Frame synchronization implementation
外包幹了四年,廢了...
Swift - Literal,字面量协议,基本数据类型、dictionary/array之间的转换
全连接层的作用是什么?
ASEMI超快恢复二极管与肖特基二极管可以互换吗