Beats 100%


  • 0
    S
    This post is deleted!

  • 1
    S

    @shiyi001 said in Beats 100%:
    这题采用了二分查找,居然击败了100%,好鸡冻好鸡冻

    class Solution {
    public

    int findMin(vector<int>& nums) {
        int len = nums.size();
        return  find(nums, 0, len-1);
    }
    
    int find(vector<int>& nums, int l, int r){
        if (l+1 == r && nums[l] > nums[r]) return nums[r];
        if (nums[l] <= nums[r]) return nums[l];
        
        int mid = (l+r)>>1;
        if (nums[mid] > nums[l]) return find(nums, mid, r);
            else return find(nums, l, mid);
    }
    

    };


Log in to reply
 

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