My 12ms c++ solution


  • 0
    Y
    class Solution {
    public:
    int min(int a, int b)
    {
    	return a < b ? a : b;
    }
    int s(vector<int> &num, int l, int r)
    {
    	if (l>r)
    		return INT_MAX;
    	if (l == r)
    		return num[l];
    	int mid = (l + r) >> 1;
    	if (num[mid] < num[r])
    		return min(num[mid], s(num, l, mid - 1));
    	else if (num[mid] > num[r])
    		return s(num, mid + 1, r);
    	else
    		return s(num, l, r - 1);
    	
    }
    int findMin(vector<int> &num) {
    	int len = num.size();
    	return s(num, 0, len - 1);
    }
    };

Log in to reply
 

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