当前位置:网站首页>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
边栏推荐
- 【NLP】HMM隐马尔可夫+维特比分词
- GIS数据处理-cesium中模型位置设置
- qt之.pro文件详解
- QT actual combat: Yunxi calendar
- QT actual combat: Yunxi chat room
- 51 Single Chip Microcomputer Design of traffic light system (with Proteus simulation, C program, schematic diagram, PCB, thesis and other complete data)
- Role of asemi rectifier module mdq100-16 in intelligent switching power supply
- [untitled]
- Branch statement of process control
- epoll 的 ET,LT工作模式———实例程序
猜你喜欢

全连接层的作用是什么?

DVWA之暴力破解(Brute Force)Low-->high

Matlab Simulink modeling and design of single-phase AC-AC frequency converter, with MATLAB simulation, PPT and papers

【STC8G2K64S4】比较器介绍以及比较器掉电检测示例程序

I thought I could lie down and enter Huawei, but I was confused when I received JD / didi / iqiyi offers one after another

利用 MATLAB 编程实现最速下降法求解无约束最优化问题
![Detailed explanation of C language knowledge points -- first knowledge of C language [1]](/img/7d/2fc527949562e1a7ef1525c7fced81.png)
Detailed explanation of C language knowledge points -- first knowledge of C language [1]

TLC5615 based multi-channel adjustable CNC DC regulated power supply, 51 single chip microcomputer, including proteus simulation and C code

成都控制板设计提供_算是详细了_单片机程序头文件的定义、编写及引用介绍

1 minute to understand the execution process and permanently master the for cycle (with for cycle cases)
随机推荐
2-Go变量操作
TLC5615 based multi-channel adjustable CNC DC regulated power supply, 51 single chip microcomputer, including proteus simulation and C code
Swift protocol Association object resource name management multithreading GCD delay once
When splicing HQL, the new field does not appear in the construction method
八路抢答器系统51单片机设计【附Proteus仿真、C程序、原理图及PCB文件、元器件清单和论文等】
Sword finger offer II 019 Delete at most one character to get palindrome (simple)
UML项目实例——抖音的UML图描述
1 minute to understand the execution process and permanently master the for cycle (with for cycle cases)
Mds55-16-asemi rectifier module mds55-16
First acquaintance with STL
Go basic reflection
Introduction to Arduino for esp8266 serial port function
如何打开Win10启动文件夹?
Swift:Entry of program、Swift调用OC、@_silgen_name 、 OC 调用Swift、dynamic、String、Substring
Pnpm installation and use
epoll 的 ET,LT工作模式———实例程序
直流可调稳压电源的Proteus仿真设计(附仿真+论文等资料)
OpenFaaS实战之四:模板操作(template)
Interviewer: let's talk about the process of class loading and the mechanism of class loading (parental delegation mechanism)
多语言通信基础 06 go实现grpc的四种数据流模式实现
