题解 | #旋转数组的最小数字#
旋转数组的最小数字
https://www.nowcoder.com/practice/9f3231a991af4f55b95579b44b7a01ba
class Solution { public: int minNumberInRotateArray(vector<int> rotateArray) { int l = 0; int r = rotateArray.size() - 1; while (l <= r) { int mid = l + (r - l) / 2; if (rotateArray[mid] > rotateArray[r]) { l = mid + 1; } else if (rotateArray[mid] < rotateArray[r]) { r = mid; } else { r--; } } return rotateArray[l]; } };
2023-剑指-搜索算法 文章被收录于专栏
2023-剑指-搜索算法