当前位置:网站首页>LeetCode153-寻找旋转排序数组中的最小值-数组-二分查找
LeetCode153-寻找旋转排序数组中的最小值-数组-二分查找
2022-04-23 14:48:00 【李烦烦搞快点】
Note:
根据nums[0]来判断是两段中的哪一段,来找到中点
一点问题要注意一下,就是最后转的全是升序的数组,找到的就是最后一个位置了,要跟nums[0]比一下输出最小的那一个
还有一个[2, 1]自己走一下就知道了 如果判断条件里带=号就不对了
代码如下:
class Solution {
public:
int findMin(vector<int>& nums) {
int l = 0, r = nums.size() - 1;
while(l < r){
int mid = l + r >> 1;
if(nums[mid] < nums[0]) r = mid;
else l = mid + 1;
}
return min(nums[0], nums[r]);
}
};
版权声明
本文为[李烦烦搞快点]所创,转载请带上原文链接,感谢
https://blog.csdn.net/Mr_Ghost812/article/details/124351252
边栏推荐
- 【STC8G2K64S4】比较器介绍以及比较器掉电检测示例程序
- Don't you know the usage scenario of the responsibility chain model?
- 2-GO variable operation
- Vous ne connaissez pas encore les scénarios d'utilisation du modèle de chaîne de responsabilité?
- 多语言通信基础 06 go实现grpc的四种数据流模式实现
- Unity_ Code mode add binding button click event
- 详解TCP的三次握手
- eolink 如何助力远程办公
- SHT11传感器的温度湿度监控报警系统单片机Proteus设计(附仿真+论文+程序等)
- Chapter 7 of JVM series -- bytecode execution engine
猜你喜欢
Eight way responder system 51 Single Chip Microcomputer Design [with Proteus simulation, C program, schematic diagram, PCB files, component list and papers, etc.]
capacitance
基于单片机的DS18B20的数字温度监控报警系统设计【LCD1602显示+Proteus仿真+C程序+论文+按键设置等】
QT interface optimization: QT border removal and form rounding
【JZ46 把数字翻译成字符串】
ASEMI超快恢复二极管与肖特基二极管可以互换吗
ASEMI整流模块MDQ100-16在智能开关电源中的作用
面试官:说一下类加载的过程以及类加载的机制(双亲委派机制)
Bingbing learning notes: take you step by step to realize the sequence table
Svn detailed use tutorial
随机推荐
拼接hql时,新增字段没有出现在构造方法中
线程同步、生命周期
MCU function signal generator, output four kinds of waveforms, adjustable frequency, schematic diagram, simulation and C program
全连接层的作用是什么?
ASEMI超快恢复二极管与肖特基二极管可以互换吗
【JZ46 把数字翻译成字符串】
pnpm安装使用
Mq-2 and DS18B20 fire temperature smoke alarm system design, 51 single chip microcomputer, with simulation, C code, schematic diagram, PCB, etc
[stc8g2k64s4] introduction of comparator and sample program of comparator power down detection
一款不错的工具:aardio
Realization of four data flow modes of grpc based on Multilingual Communication
Proteus simulation design of four storey and eight storey elevator control system, 51 single chip microcomputer, with simulation and keil c code
The art of automation
如何打开Win10启动文件夹?
压缩映射定理
Swift: entry of program, swift calls OC@_ silgen_ Name, OC calls swift, dynamic, string, substring
多语言通信基础 06 go实现grpc的四种数据流模式实现
QT actual combat: Yunxi chat room
Want to be an architect? Tamping the foundation is the most important
OpenFaaS实战之四:模板操作(template)