当前位置:网站首页>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
边栏推荐
- Pnpm installation and use
- GIS数据处理-cesium中模型位置设置
- LeetCode153-寻找旋转排序数组中的最小值-数组-二分查找
- we引用My97DatePicker 实现时间插件使用
- Interviewer: let's talk about the process of class loading and the mechanism of class loading (parental delegation mechanism)
- A blog allows you to learn how to write markdown on vscode
- 8.5 循环神经网络简洁实现
- epoll 的EPOLLONESHOT 事件———实例程序
- Sword finger offer II 019 Delete at most one character to get palindrome (simple)
- Matlab Simulink modeling and design of single-phase AC-AC frequency converter, with MATLAB simulation, PPT and papers
猜你喜欢
随机推荐
1n5408-asemi rectifier diode
OC 转 Swift 条件编译、标记、宏、 Log、 版本检测、过期提示
A good tool: aardio
多语言通信基础 06 go实现grpc的四种数据流模式实现
Detailed comparison between asemi three-phase rectifier bridge and single-phase rectifier bridge
The art of automation
[NLP] HMM hidden Markov + Viterbi word segmentation
raised exception class EAccexxViolation with ‘Access violation at address 45EFD5 in module 出错
1990年1月1日是星期一,定义函数date_to_week(year,month,day),实现功能输入年月日后返回星期几,例如date_to_week(2020,11,1),返回:星期日。 提示:
【NLP】HMM隐马尔可夫+维特比分词
Progress in the treatment of depression
Epoll's et, lt working mode -- example program
Ali developed three sides, and the interviewer's set of combined punches made me confused on the spot
When splicing HQL, the new field does not appear in the construction method
【Proteus仿真】自动量程(范围<10V)切换数字电压表
Sword finger offer II 019 Delete at most one character to get palindrome (simple)
一个月把字节,腾讯,阿里都面了,写点面经总结……
Design of single chip microcomputer Proteus for temperature and humidity monitoring and alarm system of SHT11 sensor (with simulation + paper + program, etc.)
Proteus simulation design of DC adjustable regulated power supply (with simulation + paper and other data)
LeetCode162-寻找峰值-二分-数组