当前位置:网站首页>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
边栏推荐
- Don't you know the usage scenario of the responsibility chain model?
- Svn detailed use tutorial
- ASEMI三相整流桥和单相整流桥的详细对比
- 剑指 Offer II 019. 最多删除一个字符得到回文(简单)
- Swift:Entry of program、Swift调用OC、@_silgen_name 、 OC 调用Swift、dynamic、String、Substring
- 一款不错的工具:aardio
- select 同时接收普通数据 和 带外数据
- ASEMI超快恢复二极管与肖特基二极管可以互换吗
- I/O复用的高级应用之一:非阻塞 connect———使用 select 实现(也可以用 poll 实现)
- I thought I could lie down and enter Huawei, but I was confused when I received JD / didi / iqiyi offers one after another
猜你喜欢

Detailed comparison between asemi three-phase rectifier bridge and single-phase rectifier bridge

51 Single Chip Microcomputer Design of traffic light system (with Proteus simulation, C program, schematic diagram, PCB, thesis and other complete data)

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

Parameter stack pressing problem of C language in structure parameter transmission

MySQL报错packet out of order

Swift: entry of program, swift calls OC@_ silgen_ Name, OC calls swift, dynamic, string, substring

OpenFaaS实战之四:模板操作(template)

UML project example -- UML diagram description of tiktok

Arduino for esp8266串口功能简介

面试官:说一下类加载的过程以及类加载的机制(双亲委派机制)
随机推荐
《JVM系列》 第七章 -- 字节码执行引擎
Advanced application of I / O multiplexing: Processing TCP and UDP services at the same time
I/O复用的高级应用:同时处理 TCP 和 UDP 服务
Realization of four data flow modes of grpc based on Multilingual Communication
What is the main purpose of PCIe X1 slot?
Do (local scope), initializer, memory conflict, swift pointer, inout, unsafepointer, unsafebitcast, success
One of the advanced applications of I / O reuse: non blocking connect -- implemented using select (or poll)
A blog allows you to learn how to write markdown on vscode
51 MCU flowers, farmland automatic irrigation system development, proteus simulation, schematic diagram and C code
Role of asemi rectifier module mdq100-16 in intelligent switching power supply
DVWA之暴力破解(Brute Force)Low-->high
Detailed comparison between asemi three-phase rectifier bridge and single-phase rectifier bridge
Unity_ Code mode add binding button click event
Eight way responder system 51 Single Chip Microcomputer Design [with Proteus simulation, C program, schematic diagram, PCB files, component list and papers, etc.]
Mq-2 and DS18B20 fire temperature smoke alarm system design, 51 single chip microcomputer, with simulation, C code, schematic diagram, PCB, etc
Provided by Chengdu control panel design_ It's detailed_ Introduction to the definition, compilation and quotation of single chip microcomputer program header file
8.5 循环神经网络简洁实现
压缩映射定理
成都控制板设计提供_算是详细了_单片机程序头文件的定义、编写及引用介绍
eolink 如何助力遠程辦公
