当前位置:网站首页>7. Dichotomy -- find a set of repeated or ordered but rotating arrays
7. Dichotomy -- find a set of repeated or ordered but rotating arrays
2022-07-28 10:16:00 【[email protected]】
Title Description :
- Input :numbers = [3,4,5,1,2]
Output :1 - Input :numbers = [2,2,2,0,1]
Output :0
public int minArray(int[] numbers) {
int low = 0, high = numbers.length-1;
while(low < high){
int temp = (low + high) / 2;
if(numbers[temp] > numbers[high]) low = temp + 1;
else if(numbers[temp] < numbers[high]) high = temp;
else high--;
}
return numbers[low];
}
I originally wanted to use double pointers , But beyond the time limit . It's faster to use dichotomy , Because I didn't grasp the key point , It's a question , This string of arrays , It is composed of repetition or order , That is, a string of numbers can be divided into two parts , Part of the ascending order or repetition , The other part is also ascending or repeating .
版权声明
本文为[[email protected]]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/209/202207280958224556.html
边栏推荐
猜你喜欢

7、二分法——寻找一组重复或者有序但是旋转的数组

二维前缀和

Illustrate three mainstream enterprise architecture models (recommended collection!)

Choosing a supplier service system is the first step for large health industry enterprises to move towards digital transformation

What are the highlights of B2B2C system? How to help jewelry enterprises build an omni channel multi merchant mall management system

What kind of knowledge payment system functions are more conducive to the development of the platform and lecturers?

ES(8.1)认证题目

On July 13, 2021, we collapsed like this

Why should I take the first-class constructor examination? How high is the gold content of the first-class Constructor Certificate?
![[esp32][esp idf][lvgl7.9] failed to compile with OLED IIC](/img/16/e5aa43df6ef9bdbc173fa547c85559.png)
[esp32][esp idf][lvgl7.9] failed to compile with OLED IIC
随机推荐
[cloud based co creation] Huawei cloud: metastudio digital content production line, which seamlessly integrates the virtual world with the real world
配置树莓派,过程和遇到问题
ELK实时日志分析平台
传全球半导体设备巨头或将于上海建合资工厂!
On July 13, 2021, we collapsed like this
13、哈希表——两个链表第一个公共节点
OSPF expansion configuration, routing principles, anti ring and re release
银行入职考试要点汇总
Deadlock algorithm: banker algorithm and security algorithm
QT | some summaries of signals and slots
Consul
Continue to write the greatest work based on modelarts [play with Huawei cloud]
Aqua Data Studio 18.5.0导出insert语句
centos7下安装mysql,网上文章都不太准
线程同步volatile与synchronized详解
leetcode——旋转数组的最小数字
CloudCompare&PCL 匹配点采样一致性抑制
API 网关 APISIX 在Google Cloud T2A 和 T2D 的性能测试
02.1.2.逻辑类型 bool
ADVANCE.AI出海指南助力企业出海印尼,掌握东南亚市场半边天