class Solution {
public:
int findMin(vector<int>& nums) {
if (nums.size() == 0) {
return 0;
}
return search(nums, nums[0], 0, nums.size() - 1);
}
private:
int search(vector<int>& nums, int minValue, int left, int right) {
if (left < right - 1) {
int mid = (left + right) / 2;
if (nums[left] < nums[mid]) {
minValue = min(minValue, nums[left]);
return search(nums, minValue, mid, right);
} else if (nums[left] > nums[mid]){
minValue = min(minValue, nums[right]);
return search(nums, minValue, left, mid);
} else {
return search(nums, minValue, left + 1, right);
}
}
minValue = min(minValue, nums[left]);
minValue = min(minValue, nums[right]);
return minValue;
}
};