当前位置:网站首页>LeetCode(剑指 Offer)- 11. 旋转数组的最小数字
LeetCode(剑指 Offer)- 11. 旋转数组的最小数字
2022-07-22 21:12:00 【放羊的牧码】
题目链接:点击打开链接
题目大意:略
解题思路

相关企业
- 字节跳动
- 亚马逊(Amazon)
AC 代码
- Java
// 解决方案(1)
class Solution {
public int minArray(int[] numbers) {
int min = Math.min(numbers[0], numbers[numbers.length - 1]);
for (int i = 1; i < numbers.length - 1; i++) {
if (numbers[i] >= numbers[i - 1] && numbers[i] > numbers[i + 1]) {
min = numbers[i + 1];
break;
} else if (numbers[i] < numbers[i - 1]) {
min = numbers[i];
break;
}
}
return min;
}
}
// 解决方案(2)
class Solution {
public int minArray(int[] numbers) {
int i = 0, j = numbers.length - 1;
while (i < j) {
int m = (i + j) / 2;
if (numbers[m] > numbers[j]) i = m + 1;
else if (numbers[m] < numbers[j]) j = m;
else {
int x = i;
for(int k = i + 1; k < j; k++) {
if(numbers[k] < numbers[x]) x = k;
}
return numbers[x];
}
}
return numbers[i];
}
}- C++
class Solution {
public:
int minArray(vector<int>& numbers) {
int i = 0, j = numbers.size() - 1;
while (i < j) {
int m = (i + j) / 2;
if (numbers[m] > numbers[j]) i = m + 1;
else if (numbers[m] < numbers[j]) j = m;
else {
int x = i;
for(int k = i + 1; k < j; k++) {
if(numbers[k] < numbers[x]) x = k;
}
return numbers[x];
}
}
return numbers[i];
}
};边栏推荐
- 小程序毕设作品之微信校园二手书交易小程序毕业设计成品(7)中期检查报告
- Talk about repaintboundary in fluent
- Part I sourcetree installation
- 打板遇到的问题
- 小程序毕设作品之微信校园二手书交易小程序毕业设计成品(2)小程序功能
- 最新版Ontrack EasyRecovery电脑数据恢复软件应用
- Alibaba Cloud Security Center's best practices for vulnerability repair
- [SSM]统一结果封装
- 妙用cURL
- Digital collections start the 100 billion level market
猜你喜欢

With 130 new services and functions a year, this storage "family bucket" has grown again

Why does MySQL index use b+ tree instead of jump table?

VR panoramic zoo, a zoo business card with different achievements

智能商务的数据分析平台设计与实现

Clever use of curl

Understanding service governance in distributed development

Wechat campus second-hand book trading applet graduation design finished product (8) graduation design thesis template

Is cross modal semantic alignment optimal under comparative learning--- Adaptive sparse attention alignment mechanism IEEE trans MultiMedia
![[ssm] unified result encapsulation](/img/ff/9528a062d464acee52047598af40c3.png)
[ssm] unified result encapsulation

93.(leaflet篇)leaflet态势标绘-进攻方向修改
随机推荐
Wechat hotel reservation applet graduation project (6) opening defense ppt
Leetcode 20有效的括号、33搜索旋转排序数组、88合并两个有序数组(nums1长度为m+n)、160相交链表、54螺旋矩阵、415字符相加(不能直接转Int)、reverse()函数
景联文科技提供3D点云-图像标注服务
Implementation of remove function
电子招标采购商城系统:优化传统采购业务,提速企业数字化升级
Wechat campus second-hand book trading applet graduation design finished product (1) development outline
[technology popularization] alliance chain layer2- on a new possibility
多传感器融合综述---FOV与BEV
局域网SDN技术硬核内幕 9 从软件Overlay到硬件Overlay
Information system project managers must recite the core examination points (49) contract law
(五)数电——公式化简法
Understanding service governance in distributed development
【翻译】宣布Krius--加速你对Kubernetes的监控采用
iQOO 10系列来袭 OriginOS原系统强化手机体验
Interpretation of URL structure
The new idea 2022.2 was officially released, and the new features are really fragrant
4G传输模块的功能应用
Report on the progress of writing Chinese experiments by latex
Wechat hotel reservation applet graduation project (8) graduation project thesis template
阿里云安全中心之漏洞修复最佳实践