原题链接在这里:https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/description/

题目:

Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.

(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).

Find the minimum element.

You may assume no duplicate exists in the array.

题解:

Binary Search, 与Find Peak Element类似.

如果nums[mid] < nums[r]说明右边一段是sorted的, minumum 只能出现在包括中点的左边一段.

反之, 说明左边一段是sorted的, minimum只能出现在不包括中点的右边一段.

最后返回nums[r].

Time Compelxity: O(logn). n = nums.length.

Space: O(1).

AC Java:

 class Solution {
public int findMin(int[] nums) {
int l = 0;
int r = nums.length - 1;
while(l < r){
int mid = l + (r - l) / 2;
if(nums[mid] < nums[r]){
r = mid;
}else{
l = mid + 1;
}
} return nums[l];
}
}

类似Search in Rotated Sorted ArrayFind Minimum in Rotated Sorted Array IISingle Element in a Sorted Array.

LeetCode Find Minimum in Rotated Sorted Array的更多相关文章

  1. Leetcode Find Minimum in Rotated Sorted Array 题解

    Leetcode Find Minimum in Rotated Sorted Array 题目大意: 对一个有序数组翻转, 就是随机取前K个数,移动到数组的后面,然后让你找出最小的那个数.注意,K有 ...

  2. [LeetCode] Find Minimum in Rotated Sorted Array II 寻找旋转有序数组的最小值之二

    Follow up for "Find Minimum in Rotated Sorted Array":What if duplicates are allowed? Would ...

  3. [LeetCode] Find Minimum in Rotated Sorted Array 寻找旋转有序数组的最小值

    Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 migh ...

  4. LeetCode Find Minimum in Rotated Sorted Array II

    原题链接在这里:https://leetcode.com/problems/find-minimum-in-rotated-sorted-array-ii/ 题目: Follow up for &qu ...

  5. Leetcode | Find Minimum in Rotated Sorted Array I && II

    Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 migh ...

  6. LeetCode——Find Minimum in Rotated Sorted Array II

    Question Follow up for "Find Minimum in Rotated Sorted Array": What if duplicates are allo ...

  7. Leetcode Find Minimum in Rotated Sorted Array I and II

    Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 migh ...

  8. LeetCode——Find Minimum in Rotated Sorted Array

    Description: Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 ...

  9. [LeetCode] Find Minimum in Rotated Sorted Array 二分搜索

    Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 migh ...

随机推荐

  1. WPF 中Frame + Page 的使用

    1 在window 的设计的时候 ,中间需要进行页面切换的时候,顶一个Frame <Frame Name="MainPage"  NavigationUIVisibility ...

  2. 浅谈WPF页间导航

    浅谈WPF页间导航 使用导航的目的是从一个页面进入到另一个页面.无论是预先决定的线性顺序(向导)还是基于层次的用户驱动程序(大部分网站的形式),或者动态生成的路径,主要有3种方法实现:调用Naviga ...

  3. SPOJ 3267 D-query(离散化+主席树求区间内不同数的个数)

    DQUERY - D-query #sorting #tree English Vietnamese Given a sequence of n numbers a1, a2, ..., an and ...

  4. 使用Nsight查找CE3的渲染bug

    工作临时的接的一个小任务,查找ce3引擎修改后在绘制上出的一点bug 在代码的底层调用代码做了一些修改后,场景里的绘制的问题,因为也是刚接触CE3代码,也只能通过Nsight来查找问题了.   首先用 ...

  5. Ubuntu+Nginx+PHP的最简搭建方法

    先安装: sudo apt-get install nginx php5-fpm -y 然后编辑配置文件: /etc/nginx/site-available/default 找到"loca ...

  6. 专治XP正在启动就蓝屏重启一直循环

    我5月6号发帖求助,很多同行都要说换系统.PE修复启动项等,这些早在我入行电脑行业10年前都会的.但是客户的数据是用金钱也买不到的,不能就这样给换了吧,这样也让客户小看我们搞电脑行业的了. 好说正题: ...

  7. linux 自动登录脚本

    #!/usr/bin/expect set port 22 set user xiaoming set password xiaoming123 set host 111.222.22.33 set ...

  8. linux命令篇

    普通用户登陆,充值root密码: sudo passwd root

  9. epoll 实际使用

    void DataHandle::recv() {     sleep(2);     _data_router -> readInfoHw(&mInfo);     ALOGD(SYS ...

  10. 【转】Unity3D的输入(Input)——键盘和鼠标

    http://blog.csdn.net/lingyun_blog/article/details/41451565 Unity3D使用input类控制用户的输入,输入包括了用户键盘,鼠标,触摸,重力 ...