当前位置:网站首页>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
边栏推荐
- Is asemi ultrafast recovery diode interchangeable with Schottky diode
- 博睿数据携手F5共同构建金融科技从代码到用户的全数据链DNA
- ASEMI超快恢复二极管与肖特基二极管可以互换吗
- Arduino for esp8266串口功能简介
- 利用 MATLAB 编程实现最速下降法求解无约束最优化问题
- Swift:Entry of program、Swift调用OC、@_silgen_name 、 OC 调用Swift、dynamic、String、Substring
- Using MATLAB programming to realize the steepest descent method to solve unconstrained optimization problems
- L'externalisation a duré quatre ans.
- Outsourcing for four years, abandoned
- Frame synchronization implementation
猜你喜欢
QT actual combat: Yunxi chat room
Proteus simulation design of DC adjustable regulated power supply (with simulation + paper and other data)
eolink 如何助力遠程辦公
Brute force of DVWA low -- > High
Swift - Literal,字面量协议,基本数据类型、dictionary/array之间的转换
Outsourcing for four years, abandoned
【无标题】
三、梯度下降求解最小θ
LeetCode162-寻找峰值-二分-数组
MySQL报错packet out of order
随机推荐
1 minute to understand the execution process and permanently master the for cycle (with for cycle cases)
Svn detailed use tutorial
Alexnet model
Swift - literal, literal protocol, conversion between basic data types and dictionary / array
Explanation and example application of the principle of logistic regression in machine learning
Detailed comparison between asemi three-phase rectifier bridge and single-phase rectifier bridge
A good tool: aardio
Resolve the conflict between computed attribute and input blur event
MySQL error packet out of order
在游戏世界组建一支AI团队,超参数的多智能体「大乱斗」开赛
1-初识Go语言
epoll 的 ET,LT工作模式———实例程序
Swift Protocol 关联对象 资源名称管理 多线程GCD 延迟 once
剑指 Offer II 019. 最多删除一个字符得到回文(简单)
Brute force of DVWA low -- > High
Explain TCP's three handshakes in detail
机器学习之逻辑回归(Logistic Regression)原理讲解和实例应用,果断收藏
Don't you know the usage scenario of the responsibility chain model?
如何打开Win10启动文件夹?
Sword finger offer II 019 Delete at most one character to get palindrome (simple)