当前位置:网站首页>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
边栏推荐
- Find daffodils - for loop practice
- A blog allows you to learn how to write markdown on vscode
- Matrix exchange row and column
- Interviewer: let's talk about the process of class loading and the mechanism of class loading (parental delegation mechanism)
- 1N5408-ASEMI整流二极管1N5408
- Thread synchronization, life cycle
- SQL中HAVING和WHERE的区别
- QT actual combat: Yunxi calendar
- Provided by Chengdu control panel design_ It's detailed_ Introduction to the definition, compilation and quotation of single chip microcomputer program header file
- Unity_代码方式添加绑定按钮点击事件
猜你喜欢
你还不知道责任链模式的使用场景吗?
we引用My97DatePicker 实现时间插件使用
DVWA之暴力破解(Brute Force)Low-->high
一款不错的工具:aardio
Vous ne connaissez pas encore les scénarios d'utilisation du modèle de chaîne de responsabilité?
A good tool: aardio
抑郁症治疗的进展
Swift protocol Association object resource name management multithreading GCD delay once
LeetCode 练习——396. 旋转函数
1N5408-ASEMI整流二极管1N5408
随机推荐
2-GO variable operation
8.4 循环神经网络从零实现
capacitance
Swift: entry of program, swift calls OC@_ silgen_ Name, OC calls swift, dynamic, string, substring
Outsourcing for four years, abandoned
1N5408-ASEMI整流二极管1N5408
1n5408-asemi rectifier diode
QT Detailed explanation of pro file
Swift - literal, literal protocol, conversion between basic data types and dictionary / array
epoll 的 ET,LT工作模式———实例程序
QT actual combat: Yunxi calendar
[proteus simulation] automatic range (range < 10V) switching digital voltmeter
【Proteus仿真】自动量程(范围<10V)切换数字电压表
《JVM系列》 第七章 -- 字节码执行引擎
Electronic perpetual calendar of DS1302_ 51 single chip microcomputer, month, day, week, hour, minute and second, lunar calendar and temperature, with alarm clock and complete set of data
Detailed explanation of C language P2 selection branch statement
Svn detailed use tutorial
抑郁症治疗的进展
Proteus simulation design of DC adjustable regulated power supply (with simulation + paper and other data)
解决computed属性与input的blur事件冲突问题