首页 > 代码库 > LeetCode - Find Minimum in Rotated Sorted Array

LeetCode - Find Minimum in Rotated Sorted Array

class Solution {
public:
   
    int fk(int l,int r,vector<int>& nums){
        if(nums[l]<=nums[r])return nums[l];
        int m = (l+r)/2;
        int k1 = fk(l,m,nums);
        int k2 = fk(m+1,r,nums);
        return min(k1,k2);
    }
   
    int findMin(vector<int>& nums) {
        int n = nums.size();
        return fk(0,n-1,nums);
    }
};

LeetCode - Find Minimum in Rotated Sorted Array