题解 | #旋转数组的最小数字#
旋转数组的最小数字
https://www.nowcoder.com/practice/9f3231a991af4f55b95579b44b7a01ba
class Solution { public: int minNumberInRotateArray(vector<int> rotateArray) { // 二分查找 int begin = 0; int end = rotateArray.size()-1; int mid = (end - begin)/2 + begin; while(end > begin) { // 判断哪一边是有序的 if(rotateArray[mid] > rotateArray[end]) { begin = mid + 1; } else if (rotateArray[mid] < rotateArray[end]) { end = mid; } else { end--; } mid = (end - begin)/2 + begin; } return rotateArray[begin] < rotateArray[end]? rotateArray[begin]:rotateArray[end]; } };