当前位置:网站首页>Leetcode162 - find peak - dichotomy - array
Leetcode162 - find peak - dichotomy - array
2022-04-23 14:48:00 【Li Fan, hurry up】
Note:
Two points , Every time we judge whether it is a peak , It's good which side the peak is on
However, we should unify the conditions and changes here , If we're going to look to the right , Let him compare with the previous one , So you don't cross the line
The code is as follows :
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;
}
};
版权声明
本文为[Li Fan, hurry up]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231447599654.html
边栏推荐
- One of the advanced applications of I / O reuse: non blocking connect -- implemented using select (or poll)
- 外包幹了四年,廢了...
- Swift - Literal,字面量协议,基本数据类型、dictionary/array之间的转换
- Is asemi ultrafast recovery diode interchangeable with Schottky diode
- ASEMI超快恢复二极管与肖特基二极管可以互换吗
- 编程哲学——自动加载、依赖注入与控制反转
- 51 MCU + LCD12864 LCD Tetris game, proteus simulation, ad schematic diagram, code, thesis, etc
- 抑郁症治疗的进展
- 【工厂模式详解】工厂方法模式
- 1n5408-asemi rectifier diode
猜你喜欢
Sword finger offer II 019 Delete at most one character to get palindrome (simple)
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
eolink 如何助力远程办公
[stc8g2k64s4] introduction of comparator and sample program of comparator power down detection
Model location setting in GIS data processing -cesium
Using MATLAB programming to realize the steepest descent method to solve unconstrained optimization problems
8.2 文本预处理
PCIe X1 插槽的主要用途是什么?
8.4 循环神经网络从零实现
MySQL报错packet out of order
随机推荐
QT actual combat: Yunxi chat room
QT actual combat: Yunxi calendar
Select receives both normal data and out of band data
Vous ne connaissez pas encore les scénarios d'utilisation du modèle de chaîne de responsabilité?
Set up an AI team in the game world and start the super parametric multi-agent "chaos fight"
On the insecurity of using scanf in VS
epoll 的EPOLLONESHOT 事件———实例程序
全连接层的作用是什么?
面试官:说一下类加载的过程以及类加载的机制(双亲委派机制)
Branch statement of process control
电容
Swift: entry of program, swift calls OC@_ silgen_ Name, OC calls swift, dynamic, string, substring
Unity_ Code mode add binding button click event
QT interface optimization: double click effect
Epoll's et, lt working mode -- example program
pnpm安装使用
剑指 Offer II 019. 最多删除一个字符得到回文(简单)
Role of asemi rectifier module mdq100-16 in intelligent switching power supply
Is asemi ultrafast recovery diode interchangeable with Schottky diode
Mq-2 and DS18B20 fire temperature smoke alarm system design, 51 single chip microcomputer, with simulation, C code, schematic diagram, PCB, etc