原题链接在这里: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. C#中的String.Format方法(转)

    一.定义String.Format是将指定的 String类型的数据中的每个格式项替换为相应对象的值的文本等效项. 如: (1)string p1 = "Jackie";strin ...

  2. winform学习之----将多个控件的click方法绑定到同一click方法中

             public Form3()         {             InitializeComponent();             button1.Click +=new ...

  3. C++ Ouput Exactly 2 Digits After Decimal Point 小数点后保留三位数字

    在C++编程中,有时候要求我们把数据保留小数点后几位,或是保留多少位有效数字等等,那么就要用到setiosflags和setprecision函数,记得要包含头文件#include <ioman ...

  4. javascript 数据类型 变量 类型转换运算符

    数据类型: 1.字符串(被双引号所包含的内容),小数,整数,日期时间,布尔型等. 2.变量: 都是通用类型的var,    定义一个变量格式:var a: 3.类型转换: 分为自动转换和强制转换,一般 ...

  5. 使用javabean连接数据库时遇到的问题

    1.whitespace问题.是便签了每空格如: 就会出现下面的问题.contentType前每空格.空格后就解决了 2. 这是部署问题,关闭,重新部署 追问 怎么部署? 回答 1.选中项目 F5(e ...

  6. https资料

    1.HTTPS的七个误解   http://blog.httpwatch.com/2011/01/28/top-7-myths-about-https/ 中文 http://www.cnblogs.c ...

  7. DTD约束的校验工具安装及检验(Iexmltls工具)

    通过打开我们写的dtd约束文档,我们可以看到,在我们不按规定的格式打开xml时并不能检验出错误.此时我们可以借助软件来帮助我们校验. Iexmltls是一个在IE浏览器下安装的用于检验xml约束是否正 ...

  8. lucene 3.0.2 操作进阶

    转自:Bannings http://blog.csdn.net/zhangao0086/article/details/ Analyzer(分词器) 分词器能以某种规则对关键字进行分词,将分好的词放 ...

  9. P4factory <Integration with Mininet>

    在终端A进入simple_router目录,make bm之后,执行 ./run_demo.bash 成功和Mininet进行协作: *** Creating network *** Adding h ...

  10. jedis操作redis全指南

    package com.wujintao.redis; import java.util.Date; import java.util.HashMap; import java.util.Iterat ...