Idea: This
question is actually a bit tricky. That is if the array Liman has duplicate values. For example, in the case of 3,1,1,2,2,2,2,2, this question is undoubtedly done with dichotomy. You only need to find the boundary of the last element of the array, but you are afraid of the above. In special cases, the approach here is to move the element at the end of the dividing line one place forward, and use the previous one to find the dividing line. If the previous one has duplicate values, then move forward.
Code:
class Solution {
public:
int minArray(vector<int>& numbers) {
int i = 0, j = numbers.size() - 1;
while (i < j) {
int m = (i + j) / 2;
if (numbers[m] > numbers[j]) i = m + 1;
else if (numbers[m] < numbers[j]) j = m;
else j--;
}
return numbers[i];
}
};