lintcode --寻找旋转排序数组中的最小值 II
来源:互联网 发布:网络监控光纤收发器 编辑:程序博客网 时间:2024/04/18 19:52
假设一个旋转排序的数组其起始位置是未知的(比如0 1 2 4 5 6 7 可能变成是4 5 6 7 0 1 2)。
你需要找到其中最小的元素。
数组中可能存在重复的元素。
注意事项
The array may contain duplicates.
样例
给出[4,4,5,6,7,0,1,2] 返回 0
public class Solution {
public int findMin(int[] num) {
int left = 0;
int right = num.length - 1;
while(left <right)
{
if(num[left] < num[right]) {//没有旋转
return num[left];
}
int mid = left + (right-left)/2;
if(num[left] <= num[mid]) {
left = mid + 1;
} else {
right = mid;
}
}
return num[left];
}
}
阅读全文
0 0
- LintCode-寻找旋转排序数组中的最小值 II
- lintcode 160 寻找旋转排序数组中的最小值 II
- Lintcode 寻找旋转排序数组中的最小值 II
- lintcode --寻找旋转排序数组中的最小值 II
- 寻找旋转排序数组中的最小值 II -LintCode
- LintCode-分治-寻找旋转排序数组中的最小值 II
- LintCode-寻找旋转排序数组中的最小值
- LintCode 寻找旋转排序数组中的最小值
- LintCode-寻找旋转排序数组中的最小值
- lintcode 寻找旋转排序数组中的最小值
- lintcode,寻找旋转排序数组中的最小值
- lintcode,寻找旋转排序数组中的最小值
- LintCode : 寻找旋转排序数组中的最小值
- lintcode--寻找旋转排序数组中的最小值
- 寻找旋转排序数组中的最小值-LintCode
- 寻找旋转排序数组中的最小值 II
- 寻找旋转排序数组中的最小值 II
- 寻找旋转排序数组中的最小值 II
- Linux的内存理解
- 环形对列(circle queue 1329 P103)
- maven查询网站
- poj2349 Kruskal题解
- 网易2017内推 [编程题] 交错01串@Java
- lintcode --寻找旋转排序数组中的最小值 II
- Superset搭建
- Java虚拟机对象创建管理与垃圾回收知识整理与分析
- Leetcode算法学习日志-121 Best Time to Buy and Sell Stock
- CVE-2015-2545浅析-word释放重引用漏洞
- Java-JDK动态代理
- NOIP 2000年提高组复赛 单词接龙
- 51nod 1289大鱼吃小鱼 模拟 单调栈
- 各种demo:css实现三角形,css大小梯形,svg使用