lintcode--寻找旋转排序数组中的最小值
来源:互联网 发布:印第安保留地知乎 编辑:程序博客网 时间:2024/04/20 05:24
假设一个旋转排序的数组其起始位置是未知的(比如0 1 2 4 5 6 7 可能变成是4 5 6 7 0 1 2)。
你需要找到其中最小的元素。
你可以假设数组中不存在重复的元素。
注意事项
You may assume no duplicate exists in the array.
给出[4,5,6,7,0,1,2] 返回 0
/**
* 定义两个指针,start,end,取中间值,
* 分别与俩指针比较,决定在那边查找
*///博客
public class Solution {
public int findMin(int[] nums) {
// write your code here
int start = 0;int end = nums.length-1;
while(start<end){
if(nums[start] < nums[end]) {//没有旋转
return nums[start];
}
int mid = start + (end-start)/2;
if(nums[start]<=nums[mid]){//只有等于才能退出,和return
start = mid+1;
}else {//nums[start]>nums[mid]
end= mid;
}
}
return nums[start];
}
}
- LintCode-寻找旋转排序数组中的最小值
- LintCode 寻找旋转排序数组中的最小值
- LintCode-寻找旋转排序数组中的最小值
- lintcode 寻找旋转排序数组中的最小值
- lintcode,寻找旋转排序数组中的最小值
- lintcode,寻找旋转排序数组中的最小值
- LintCode : 寻找旋转排序数组中的最小值
- lintcode--寻找旋转排序数组中的最小值
- 寻找旋转排序数组中的最小值-LintCode
- LintCode-寻找旋转排序数组中的最小值 II
- lintcode- 寻找旋转排序数组中的最小值-159
- LintCode-剑指Offer-(159)寻找旋转排序数组中的最小值
- LintCode-剑指Offer-(28)寻找旋转排序数组中的最小值
- 寻找旋转排序数组中的最小值——LintCode
- lintcode 160 寻找旋转排序数组中的最小值 II
- Lintcode 寻找旋转排序数组中的最小值 II
- [LintCode]159.寻找旋转排序数组中的最小值
- lintcode --寻找旋转排序数组中的最小值 II
- 每日英语阅读(三十三)
- 2017.08.10【NOIP提高组】模拟赛B组
- Linux与Windows共享文件夹之samba的安装与使用(Ubuntu为例)
- 51nod 1090 3个数和为0 二分暴力。
- LWIP的IGMP
- lintcode--寻找旋转排序数组中的最小值
- C++ Primer Notes(7)
- 从同步异步、阻塞非阻塞到5种IO模型
- return -1意义
- 进程与线程的联系与区别
- Gameia HDU 6105
- DKSVD字典学习的脸部识别
- [Leetcode] 353. Design Snake Game 解题报告
- 布隆过滤器与位图