题解 | #旋转数组的最小数字#
旋转数组的最小数字
https://www.nowcoder.com/practice/9f3231a991af4f55b95579b44b7a01ba
class Solution { public: int minNumberInRotateArray(vector<int> rotateArray) { int i = floor(rotateArray.size() / 2); int j = ceil(rotateArray.size() / 2); while (i > 0 && j < rotateArray.size()) { if (rotateArray[i - 1] <= rotateArray[i]) i--; else return rotateArray[i]; if (rotateArray[j] <= rotateArray[j + 1]) j++; else return rotateArray[j + 1]; } if(i == 0) return rotateArray[0]; return rotateArray[rotateArray.size()-1]; } };