It is precisely because of this condition, there is a more complex case, even affect the algorithm's time complexity. It turns out that we rely on the relationship between the middle and the edge elements to determine which half is unaffected by rotate and still orderly. And now because of the repetition, if we encounter the middle and edge of the same situation, we lose the side of the order of information, because the side can be ordered results. Assuming that the original array is {1,2,3,3,3,3,3}, then the rotation may be {3,3,3,3,3,1,2}, or {3,1,2,3,3,3,3}, so that we judge the left edge and center of the time are 3, if we are looking for 1 or 2, We don't know which half we should jump to. The solution can only be to move the edge one step, until the edge and the middle is not equal or meet, which leads to the possibility that there will not be half cut. So the worst case scenario (such as all an element, or only one element is different from the other, and he is in the last one) will appear each move one step, a total of n steps, the algorithm's time complexity into O (n).
Like the last one, it's just a little bit more complicated.
BOOL Rotatedarray_second (vector<int>& vec,int key) {int low =0,high= vec.size () -1;int mid;while (Low <= high ) {cout<<low<< "" <
Search in rotated Sorted Array Ii-leetcode