题解 | #旋转数组的最小数字#
旋转数组的最小数字
http://www.nowcoder.com/practice/9f3231a991af4f55b95579b44b7a01ba
class Solution {
public:
int minNumberInRotateArray(vector<int> rotateArray) {
int l = 0, r = rotateArray.size() - 1;
// 二分法
while(l < r) {
int mid = (l + r) / 2;
if(rotateArray[mid] > rotateArray[r]) {
l = mid + 1;
}
// 单独处理中间值等于右边值的情况
else if(rotateArray[mid] == rotateArray[r])
r--;
else {
r = mid;
}
}
return rotateArray[l];
}
};