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

    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.

    class Solution{
    public:
        int findMin(vector<int>& nums){
            int size = nums.size();
            int left = 0;
            int right = size - 1;
            int mid;
            while(left < right){
                mid = (left + right)/2;
                if(nums[mid] > nums[right])
                    left = mid+1;
                else if(nums[mid] < nums[right])
                    right = mid;
                else 
                    right--;
            }
            return nums[left];
        }
    };
  • 相关阅读:
    4d
    加载数据
    刘亮给的帮助
    加载数据
    选中并高亮显示
    ArcEngine
    接口编程
    好的参考文献
    在本地安装 wordpress
    C#读取EXCEL数据
  • 原文地址:https://www.cnblogs.com/wxquare/p/5947276.html
Copyright © 2011-2022 走看看