当前位置:网站首页>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
边栏推荐
- QT interface optimization: QT border removal and form rounding
- Using MATLAB programming to realize the steepest descent method to solve unconstrained optimization problems
- 你還不知道責任鏈模式的使用場景嗎?
- Pnpm installation and use
- we引用My97DatePicker 实现时间插件使用
- Realization of four data flow modes of grpc based on Multilingual Communication
- 一款不错的工具:aardio
- 面试官:说一下类加载的过程以及类加载的机制(双亲委派机制)
- 三、梯度下降求解最小θ
- 自动化的艺术
猜你喜欢

MCU function signal generator, output four kinds of waveforms, adjustable frequency, schematic diagram, simulation and C program

We reference My97DatePicker to realize the use of time plug-in

SVN详细使用教程

你還不知道責任鏈模式的使用場景嗎?

Arduino for esp8266串口功能简介

Don't you know the usage scenario of the responsibility chain model?

一个月把字节,腾讯,阿里都面了,写点面经总结……

电容

LeetCode165-比较版本号-双指针-字符串

Swift Protocol 关联对象 资源名称管理 多线程GCD 延迟 once
随机推荐
【JZ46 把数字翻译成字符串】
【Servlet】Servlet 详解(使用+原理)
vscode中文插件不生效问题解决
Detailed explanation of C language knowledge points -- first knowledge of C language [1]
eolink 如何助力遠程辦公
Arduino for esp8266串口功能简介
Epolloneshot event of epoll -- instance program
UML project example -- UML diagram description of tiktok
qt之.pro文件详解
QT interface optimization: QT border removal and form rounding
外包干了四年,废了...
Achievements in science and Technology (21)
【工厂模式详解】工厂方法模式
Raised exception class eaccexviolation with 'access violation at address 45efd5 in module error
Don't you know the usage scenario of the responsibility chain model?
Swift:Entry of program、Swift调用OC、@_silgen_name 、 OC 调用Swift、dynamic、String、Substring
Svn detailed use tutorial
DVWA之暴力破解(Brute Force)Low-->high
Frame synchronization implementation
ASEMI超快恢复二极管与肖特基二极管可以互换吗
