my clear C++ solution beats 33.49%


  • 0
    F
    class Solution {
    public:
        int findMin(vector<int>& nums) {
            int left=0,right=nums.size()-1;
            int re=INT_MAX;
            while(left<right) {
                int mid = left + (right - left) / 2;
                if (nums[mid] > nums[left]) {
                    re = min(nums[left], re);
                    left = mid + 1;
                } else if(nums[mid] < nums[left]){
                    right = mid;
                }else{
                    re = min(nums[left], re);
                    bool flag=false;//表示left与mid之间没有比left小的
                    for(int i=left+1;i<mid;i++){
                        if(nums[i]<nums[left]) flag=true;
                    }
                    if(flag) right=mid;
                    else left=mid+1;
                }
    
            }
            re=min(re,nums[left]);
            return re;
        }
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.