当前位置:网站首页>Leetcode153 - find the minimum value in the rotation sort array - array - binary search
Leetcode153 - find the minimum value in the rotation sort array - array - binary search
2022-04-23 14:48:00 【Li Fan, hurry up】
Note:
according to nums[0] To determine which of the two paragraphs , To find the midpoint
There's a little problem to pay attention to , That is, the last array is all in ascending order , What we found is the last position , Want to follow nums[0] Compare the one with the smallest output
One more [2, 1] Just walk by yourself If the judgment conditions include = The number is wrong
The code is as follows :
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]);
}
};
版权声明
本文为[Li Fan, hurry up]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231447599777.html
边栏推荐
- 555 timer + 74 series chip to build eight way responder, 30s countdown, proteus simulation, etc
- Swift - literal, literal protocol, conversion between basic data types and dictionary / array
- Achievements in science and Technology (21)
- 在游戏世界组建一支AI团队,超参数的多智能体「大乱斗」开赛
- Introduction to Arduino for esp8266 serial port function
- Explain TCP's three handshakes in detail
- Chapter 7 of JVM series -- bytecode execution engine
- Arduino for esp8266串口功能简介
- [proteus simulation] automatic range (range < 10V) switching digital voltmeter
- UML project example -- UML diagram description of tiktok
猜你喜欢
Brute force of DVWA low -- > High
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)
在游戏世界组建一支AI团队,超参数的多智能体「大乱斗」开赛
A good tool: aardio
你還不知道責任鏈模式的使用場景嗎?
8.2 文本预处理
想要成为架构师?夯实基础最重要
外包幹了四年,廢了...
LeetCode153-寻找旋转排序数组中的最小值-数组-二分查找
8.5 循环神经网络简洁实现
随机推荐
【无标题】
[jz46 translate numbers into strings]
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)
线程同步、生命周期
When splicing HQL, the new field does not appear in the construction method
AT89C52 MCU frequency meter (1Hz ~ 20MHz) design, LCD1602 display, including simulation, schematic diagram, PCB and code, etc
epoll 的EPOLLONESHOT 事件———实例程序
成都控制板设计提供_算是详细了_单片机程序头文件的定义、编写及引用介绍
一个月把字节,腾讯,阿里都面了,写点面经总结……
【STC8G2K64S4】比较器介绍以及比较器掉电检测示例程序
OC 转 Swift 条件编译、标记、宏、 Log、 版本检测、过期提示
[proteus simulation] automatic range (range < 10V) switching digital voltmeter
I/O复用的高级应用:同时处理 TCP 和 UDP 服务
Bingbing learning notes: take you step by step to realize the sequence table
PCIe X1 插槽的主要用途是什么?
Go basic reflection
Interviewer: let's talk about the process of class loading and the mechanism of class loading (parental delegation mechanism)
Alexnet model
Resolve the conflict between computed attribute and input blur event
博睿数据携手F5共同构建金融科技从代码到用户的全数据链DNA