/**
* Created by WQC on 2017/7/18.
* Find the smallest number of rotated arrays
* Move a number of elements at the beginning of an array to the end of the array, called the rotation of the array
* Enter a rotation of an incrementally sorted array, output the smallest element of the rotated array
* For example: 3,4,5,1,2 is a rotation of 1,2,3,4,5, the minimum value is 1
*/
public class Problem8_findminnumber {
Public Integer Findminnum (int[] array)
{
if (array = = NULL)
{
return null;
}
int leftindex = 0;
int Rightindex =array.length-1;
int mid = 0;
while (Array[leftindex]>=array[rightindex])
{
if (Rightindex-leftindex <= 1)
{
MID = Rightindex;
Break
}
Mid = (Leftindex + rightindex)/2;
if (array[leftindex] = = Array[rightindex] && Array[leftindex] = = Array[mid])
{
if (Array[leftindex + 1]! = Array[rightindex-1])
{
MID = Array[leftindex + 1] < array[rightindex-1]? (Leftindex + 1): (rightIndex-1);
Break
}else{
leftindex++;
rightindex--;
}
}else if (Array[mid] >= Array[leftindex]) {
Leftindex = mid;
}else if (Array[mid] <= Array[rightindex]) {
Rightindex = mid;
}
}
return Array[mid];
}
}
Sword refers to offer Java-find the smallest number of rotated arrays