当前位置:网站首页>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
边栏推荐
- 【Servlet】Servlet 详解(使用+原理)
- SQLSERVER事物与锁的问题
- Want to be an architect? Tamping the foundation is the most important
- TLC5615 based multi-channel adjustable CNC DC regulated power supply, 51 single chip microcomputer, including proteus simulation and C code
- AT89C52 MCU frequency meter (1Hz ~ 20MHz) design, LCD1602 display, including simulation, schematic diagram, PCB and code, etc
- 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.)
- DVWA之暴力破解(Brute Force)Low-->high
- Ali developed three sides, and the interviewer's set of combined punches made me confused on the spot
- First acquaintance with STL
猜你喜欢
1-初识Go语言
机器学习之逻辑回归(Logistic Regression)原理讲解和实例应用,果断收藏
SVN详细使用教程
Thread synchronization, life cycle
Explain TCP's three handshakes in detail
LeetCode165-比较版本号-双指针-字符串
555 timer + 74 series chip to build eight way responder, 30s countdown, proteus simulation, etc
博睿数据携手F5共同构建金融科技从代码到用户的全数据链DNA
编程哲学——自动加载、依赖注入与控制反转
一个月把字节,腾讯,阿里都面了,写点面经总结……
随机推荐
Unity_ Code mode add binding button click event
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)
8.5 循环神经网络简洁实现
Want to be an architect? Tamping the foundation is the most important
QT actual combat: Yunxi chat room
We reference My97DatePicker to realize the use of time plug-in
三、梯度下降求解最小θ
【Servlet】Servlet 详解(使用+原理)
【Proteus仿真】自动量程(范围<10V)切换数字电压表
全连接层的作用是什么?
QT Detailed explanation of pro file
Epoll's et, lt working mode -- example program
帧同步 实现
How do I open the win10 startup folder?
Find daffodils - for loop practice
Explanation and example application of the principle of logistic regression in machine learning
科技的成就(二十一)
一款不错的工具:aardio
vscode中文插件不生效问题解决
【STC8G2K64S4】比较器介绍以及比较器掉电检测示例程序