当前位置:网站首页>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
边栏推荐
- Swift:Entry of program、Swift调用OC、@_silgen_name 、 OC 调用Swift、dynamic、String、Substring
- QT interface optimization: QT border removal and form rounding
- Proteus simulation design of DC adjustable regulated power supply (with simulation + paper and other data)
- 阿里研发三面,面试官一套组合拳让我当场懵逼
- Resolve the conflict between computed attribute and input blur event
- Set up an AI team in the game world and start the super parametric multi-agent "chaos fight"
- 成都控制板设计提供_算是详细了_单片机程序头文件的定义、编写及引用介绍
- A good tool: aardio
- The art of automation
- ASEMI整流模块MDQ100-16在智能开关电源中的作用
猜你喜欢
The art of automation
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)
详解TCP的三次握手
电容
we引用My97DatePicker 实现时间插件使用
GIS数据处理-cesium中模型位置设置
Detailed comparison between asemi three-phase rectifier bridge and single-phase rectifier bridge
do(Local scope)、初始化器、内存冲突、Swift指针、inout、unsafepointer、unsafeBitCast、successor、
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
全连接层的作用是什么?
随机推荐
三、梯度下降求解最小θ
Pnpm installation and use
Branch statement of process control
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)
Role of asemi rectifier module mdq100-16 in intelligent switching power supply
AT89C52 MCU frequency meter (1Hz ~ 20MHz) design, LCD1602 display, including simulation, schematic diagram, PCB and code, etc
【JZ46 把数字翻译成字符串】
Using MATLAB programming to realize the steepest descent method to solve unconstrained optimization problems
Sword finger offer II 019 Delete at most one character to get palindrome (simple)
Mds55-16-asemi rectifier module mds55-16
go基础 反射
SHT11传感器的温度湿度监控报警系统单片机Proteus设计(附仿真+论文+程序等)
Swift protocol Association object resource name management multithreading GCD delay once
Vous ne connaissez pas encore les scénarios d'utilisation du modèle de chaîne de responsabilité?
QT interface optimization: QT border removal and form rounding
Master in minutes --- ternary operator (ternary operator)
[stc8g2k64s4] introduction of comparator and sample program of comparator power down detection
OpenFaaS实战之四:模板操作(template)
redis的五种数据类型
GIS数据处理-cesium中模型位置设置