1. Find Minimum in Rotated Sorted Array II

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.

The array may contain duplicates.

Example 1:

Input: [1,3,5]
Output: 1

Example 2:

Input: [2,2,2,0,1]
Output: 0

Note:

三种情况





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

【刷题-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 寻找旋转有序数组的最小值之二

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

  3. Java for LeetCode 154 Find Minimum in Rotated Sorted Array II

    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 154. Find Minimum in Rotated Sorted Array II --------- java

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

  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

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

  7. 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. ( ...

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

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

  9. 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 ...

随机推荐

  1. java 多线程 :ThreadLocal 共享变量多线程不同值方案;InheritableThreadLocal变量子线程中自定义值,孙线程可继承

      ThreadLocal类的使用 变量值的共享可以使用public static变量的形式,所有的线程都是用同一个public static变量.如果想实现每一个线程都有自己的值.该变量可通过Thr ...

  2. 20款GitHub上优秀的Go开源项目

    docker 无人不知的虚拟华平台,开源的应用容器引擎,借助该引擎,开发者可以打包他们的应用,移植到任何平台上. https://github.com/docker/docker 38154 star ...

  3. JAVA获取当前日期的下周一到下周日的所有日期集合

    /** * 获取当前日期的下周一到下周日的所有日期集合 * @return */ public static List getNextWeekDateList(){ Calendar cal1 = C ...

  4. ORACLE数据库登录显示ORA-28001: the password has expired

    Oracle数据库登录显示 "这个密码已过期,请输入新密码" 点击win键 找到Oracle的SQL Plus 点击打开之后输入登录的用户名密码,然后会显示该密码已过期,输入新口令 ...

  5. C语言获取字符年月日时分秒毫秒

    概述 本文演示环境: Windows10 使用C语言获取年月日时分秒毫秒, 代码 #include <iostream> #include <string> #include ...

  6. 平衡二叉树(c++)实现(存在问题:插入节点后,问题:调整树的结构存在问题)

    !!版权声明:本文为博主原创文章,版权归原文作者和博客园共有,谢绝任何形式的 转载!! 作者:mohist 更新那时间: 22:13  03-02-2020  逻辑存在问题:插入节点后,调整数的结构不 ...

  7. 一个简单的基于epoll的udp接收

    --- 1 #include <iostream> 2 #include <sys/epoll.h> 3 #include <fcntl.h> 4 #include ...

  8. JS中常见的几种控制台台报错

    Error 控制台报错 EvalError 全局错误RangeError 引用错ReferenceError 参数错误SyntaxError 语法错误TypeError 类型错误URIError 编码 ...

  9. 使用 JavaScript 的 HTML 页面混合、JavaScript 文件引用和 HTML 代码嵌入 3 种方式在 HTML 页面上打印出“点击我进入到百度首页”的超链接

    查看本章节 查看作业目录 需求说明: 使用 JavaScript 的 HTML 页面混合.JavaScript 文件引用和 HTML 代码嵌入 3 种方式在 HTML 页面上打印出"点击我进 ...

  10. 编写Java程序,实现简单的五子棋博弈游戏(美和易思Java练习习题)

    package com.qq.gb; import java.util.Scanner; public class GoBang { Scanner sc = new Scanner(System.i ...