zoukankan      html  css  js  c++  java
  • leetcode------Find Minimum in Rotated Sorted Array II

    标题: Find Minimum in Rotated Sorted Array II
    通过率: 31.1%
    难度:

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

    Would this affect the run-time complexity? How and why?

    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.

    再第一版本中我已经详细介绍了旋转数组的特点。

    Find Minimum in Rotated Sorted Array可以直接点击去看我对于旋转数组的分析。本题直接看代码

     1 public class Solution {
     2     public int findMin(int[] num) {
     3         int start=0,end=num.length-1,mid=0;
     4         while(start<end&&num[start]>=num[end]){
     5             mid=(start+end)/2;
     6             if(num[mid]>num[end])start=mid+1;
     7             else if(num[mid]<num[end])end=mid;
     8             else start+=1;
     9         }
    10         return num[start];
    11     }
    12 }
  • 相关阅读:
    gcvt(),ecvt(),fcvt()的区别
    SQLITE3 使用总结
    C++的类型转换浅析
    JAVA Class21
    JAVA Class20
    JAVA Class19
    JAVA Class18
    JAVA Class17
    JAVA Class16
    关于hover失效问题(!important)
  • 原文地址:https://www.cnblogs.com/pkuYang/p/4292639.html
Copyright © 2011-2022 走看看