The title describes moving a number of elements at the beginning of an array to the end of the array, which we call the rotation of the array.
Enter a rotation of a non-descending sorted array, outputting the smallest element of the rotated array.
For example, the array {3,4,5,1,2} is a rotation of {1,2,3,4,5}, and the minimum value of the array is 1.
Note: All elements given are greater than 0, and if the array size is 0, return 0.
classSolution { Public: intMinnumberinrotatearray (vector<int>Rotatearray) { if(rotatearray.size () = =0) return 0; intIndex1 =0; intIndex2 = Rotatearray.size ()-1; intIndexmid =index1; while(Rotatearray[index1] >=Rotatearray[index2]) { if(Index2-index1 = =1) {Indexmid=Index2; Break; } Indexmid= (INDEX1+INDEX2)/2; if(Rotatearray[indexmid] >=rotatearray[index1]) index1=Indexmid; Else if(Rotatearray[indexmid] <=Rotatearray[index2]) index2=Indexmid; } returnRotatearray[indexmid]; }};
Minimum number of rotated array