暴力
class Solution {
public:
int minNumberInRotateArray(vector<int> rotateArray) {
sort(rotateArray.begin(), rotateArray.end());
return rotateArray[0];
}
};
特殊的二分
class Solution {
public:
int minNumberInRotateArray(vector<int> rotateArray) {
if(rotateArray.size()==0) return 0;
int r=rotateArray.size()-1;
int l=0;
int mid=0;
while(l<r){
if(rotateArray[l]<rotateArray[r]) return rotateArray[l];
mid=l+(r-l)/2;
if(rotateArray[mid]>rotateArray[l]){
l=mid+1;
}
else if(rotateArray[mid]<rotateArray[r]){
r=mid;
}
else l++;
}
return rotateArray[l];
}
};