Suppose a sorted array is rotated at some pivot unknown to you beforehand.
(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).
Find the minimum element.
You may assume no duplicate exists in the array.
class Solution {
public:
int findMin(vector<int> &num) {
if(num[0] <= num[num.size() - 1]){
return num[0];
}
int leftIndex = 0;
int rightIndex = num.size() - 1;
while((leftIndex + 1) < rightIndex){
int midIndex = (leftIndex + rightIndex) / 2;
if(num[midIndex] < num[leftIndex]){
rightIndex = midIndex;
}else{
leftIndex = midIndex;
}
}
return min(num[leftIndex], num[rightIndex]);
}
};http://www.waitingfy.com/archives/1630
LeetCode Find Minimum in Rotated Sorted Array
原文:http://blog.csdn.net/fox64194167/article/details/44245529