Suppose a sorted array 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.

The array may contain duplicates.

解题思路:

参考Java for LeetCode 081 Search in Rotated Sorted Array II JAVA实现如下:

  1. public int findMin(int[] nums) {
  2. int left = 0, right = nums.length - 1, res = nums[0];
  3. while (left <= right) {
  4. res = Math.min(nums[left],Math.min(res, nums[(right + left) / 2]));
  5. if (nums[(right + left) / 2] < nums[left])
  6. right = (right + left) / 2 - 1;
  7. else if (nums[(right + left) / 2] > nums[left])
  8. left = (right + left) / 2 + 1;
  9. else
  10. left++;
  11. }
  12. return res;
  13. }

Java for LeetCode 154 Find Minimum in Rotated Sorted Array II的更多相关文章

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

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

  2. leetcode 154. Find Minimum in Rotated Sorted Array II --------- java

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

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

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

  4. [LeetCode#154]Find Minimum in Rotated Sorted Array II

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

  5. LeetCode 154. Find Minimum in Rotated Sorted Array II寻找旋转排序数组中的最小值 II (C++)

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

  6. LeetCode 154.Find Minimum in Rotated Sorted Array II(H)(P)

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

  7. 【LeetCode】154. Find Minimum in Rotated Sorted Array II 解题报告(Python)

    [LeetCode]154. Find Minimum in Rotated Sorted Array II 解题报告(Python) 标签: LeetCode 题目地址:https://leetco ...

  8. leetcode 153. Find Minimum in Rotated Sorted Array 、154. Find Minimum in Rotated Sorted Array II 、33. Search in Rotated Sorted Array 、81. Search in Rotated Sorted Array II 、704. Binary Search

    这4个题都是针对旋转的排序数组.其中153.154是在旋转的排序数组中找最小值,33.81是在旋转的排序数组中找一个固定的值.且153和33都是没有重复数值的数组,154.81都是针对各自问题的版本1 ...

  9. 【LeetCode】154. Find Minimum in Rotated Sorted Array II (3 solutions)

    Find Minimum in Rotated Sorted Array II Follow up for "Find Minimum in Rotated Sorted Array&quo ...

随机推荐

  1. 【HDU 2604】Queuing

    题 题意 f和m两种字母组成字符串,fmf 和 fff 这种为不安全的字符串,现在有2*L个字母,问你有多少安全的字符串.答案mod M. 分析 递推,这题本意是要用矩阵快速幂.不过我发现这题好神奇, ...

  2. firefox(ff)下无法显示bootstrap图标问题的解决方案(转)

    原文链接: http://www.th7.cn/web/html-css/201502/82548.shtml 后在网上搜到了解决方案,在此分享以供各位遇到问题的同好参考:在ff的地址栏中输入“abo ...

  3. C#获取本机的MAC地址

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.M ...

  4. Mybatis的ResultMap的使用

    本篇文章通过一个实际工作中遇到的例子开始吧: 工程使用Spring+Mybatis+Mysql开发.具体的业务逻辑很重,对象之间一层一层的嵌套.和数据库表对应的是大量的model类,而和前端交互的是V ...

  5. Xcode的一些有用的插件

    ** --Alcatraz:Xcode插件管理  ** 安装:curl -fsSL https://raw.github.com/supermarin/Alcatraz/master/Scripts/ ...

  6. IOC 构造函数注入vs属性注入

    1.不管是构造函数注入还是属性注入,都要先把对象给new 出来,构造函数应该也是public.2.一般使用 配置文件,属性注入,不用使用特性,直接配置,初始化或依赖,凡是注入的,都要有访问权限,pub ...

  7. ECSHOP编辑器Fckeditor上传图片中文名称乱码的解决方法

    ECSHOP编辑器Fckeditor上传图片中文名称乱码的解决方法 ECSHOP教程/ ecshop教程网(www.ecshop119.com) 2015-02-11   中文名乱码是因为:FCKed ...

  8. Get与Post比较

  9. hdu 1284 钱币兑换问题(动态规划)

    Ac code : 完全背包: #include<stdio.h> #include<string.h> int dp[4][40000]; int main(void) { ...

  10. find只查当前目录 和 -exec和xargs区别

    1.find默认查找当前目录和子目录,通过maxdepth限制只查当前目录: find . -maxdepth 1 -type f -name "*.php" 2. find . ...