Find Minimum in Rotated Sorted Array II

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

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

Write a function to determine if a given target is in the array.

 

my solution is accepted. but there are something i haven't figure out待我想明白,再解释

class Solution {
public:
    int findMin(vector<int> &num) {
        int low=0;
        int hi=num.size()-1;
        int mid=0;
        while(low<hi){
            mid=(low+hi)/2;
            if(num[mid]>=num[hi]) low=mid+1;
            else hi=mid;
        }
        int min=low;
        for(int i=low;i>=0;i--){
            if(i==0) {min=i;break;}
            if(num[i-1]>num[i]) {
                min=i;
                break;
            }
        }
        return num[min];
    }
};

 

posted @ 2015-03-12 14:52  jasmine_turnsoul  阅读(107)  评论(0编辑  收藏  举报