当前位置:网站首页>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
边栏推荐
- Prometheus operation and maintenance tool promtool (IV) TSDB function
- Digital transformation scheme of real estate: all-round digital intelligence system operation, helping real estate enterprises improve the effectiveness of management and control
- 胡润发布2020中国芯片设计10强民营企业:华为海思竟然没有上榜!
- CGAL编译错误
- Sort - quick sort (fast and slow pointer Implementation)
- Choosing a supplier service system is the first step for large health industry enterprises to move towards digital transformation
- 14、双指针——盛最多水的容器
- Redis interview questions must be known and learned
- Elk real time log analysis platform
- 配置树莓派,过程和遇到问题
猜你喜欢

什么样的知识付费系统功能,更有利于平台与讲师发展?

Flink - checkpoint Failure reason: Not all required tasks are currently running

【JZOF】14剪绳子

21. 合并两个有序链表
![[learning notes] border and period](/img/a4/5493f7eefc7dd0e38bc9a53a92b87b.png)
[learning notes] border and period

SuperMap iServer发布管理以及调用地图服务

office2013以上输入数学公式

记录一次idea中的父子项目修改project与module名称,亲测!

MySQL架构原理

Why should I take the first-class constructor examination? How high is the gold content of the first-class Constructor Certificate?
随机推荐
[esp32][esp idf] ap+sta realizes wireless bridging and transferring WiFi signals
10 minute quick start EVs [play Huawei cloud]
Vulnerability analysis hevd-0x8.integeroverflow[win7x86]
Prometheus operation and maintenance tool promtool (IV) TSDB function
Holy Grail of web and double wing layout, float, clear, both
Etcd(高可用KV数据库)
定了!就在7月30日!
JWT login authentication + token automatic renewal scheme, well written!
ADVANCE.AI出海指南助力企业出海印尼,掌握东南亚市场半边天
[jzof] 14 cut rope
CloudCompare&PCL 匹配点采样一致性抑制
Sort - quick sort (fast and slow pointer Implementation)
Aqua Data Studio 18.5.0导出insert语句
pt-kill 查询中包含中文字符 导致工具失效的排查
Lucene 查询语法备忘
【JZOF】14剪绳子
DBeaver的操作日志
印度计划禁用中国电信设备!真离得开华为、中兴?
第四步-用户开发环境设置
[esp32][esp idf][lvgl7.9] failed to compile with OLED IIC