当前位置:网站首页>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
边栏推荐
- capacitance
- Ali developed three sides, and the interviewer's set of combined punches made me confused on the spot
- Progress in the treatment of depression
- [untitled]
- Role of asemi rectifier module mdq100-16 in intelligent switching power supply
- do(Local scope)、初始化器、内存冲突、Swift指针、inout、unsafepointer、unsafeBitCast、successor、
- Explanation and example application of the principle of logistic regression in machine learning
- 科技的成就(二十一)
- 《JVM系列》 第七章 -- 字节码执行引擎
- Branch statement of process control
猜你喜欢
UML项目实例——抖音的UML图描述
中富金石财富班29800效果如何?与专业投资者同行让投资更简单
Detailed explanation of C language knowledge points -- first knowledge of C language [1]
Vous ne connaissez pas encore les scénarios d'utilisation du modèle de chaîne de responsabilité?
51 MCU + LCD12864 LCD Tetris game, proteus simulation, ad schematic diagram, code, thesis, etc
Do (local scope), initializer, memory conflict, swift pointer, inout, unsafepointer, unsafebitcast, success
Don't you know the usage scenario of the responsibility chain model?
555 timer + 74 series chip to build eight way responder, 30s countdown, proteus simulation, etc
Swift Protocol 关联对象 资源名称管理 多线程GCD 延迟 once
Is asemi ultrafast recovery diode interchangeable with Schottky diode
随机推荐
Do (local scope), initializer, memory conflict, swift pointer, inout, unsafepointer, unsafebitcast, success
select 同时接收普通数据 和 带外数据
全连接层的作用是什么?
外包干了四年,废了...
ASEMI三相整流桥和单相整流桥的详细对比
Unity_ Code mode add binding button click event
[detailed explanation of factory mode] factory method mode
eolink 如何助力遠程辦公
Outsourcing for four years, abandoned
Multisim Simulation Design of DC adjustable regulated power supply of LM317 (with simulation + paper + reference)
Introduction to Arduino for esp8266 serial port function
3、 Gradient descent solution θ
抑郁症治疗的进展
Sword finger offer II 019 Delete at most one character to get palindrome (simple)
epoll 的 ET,LT工作模式———实例程序
成都控制板设计提供_算是详细了_单片机程序头文件的定义、编写及引用介绍
LeetCode165-比较版本号-双指针-字符串
51 MCU flowers, farmland automatic irrigation system development, proteus simulation, schematic diagram and C code
Programming philosophy - automatic loading, dependency injection and control inversion
Detailed explanation of C language knowledge points -- first knowledge of C language [1]