Title: The smallest number of rotating arrays moves a number of the first elements of an array to the end of the array, which we call the rotation of the array. Enter a rotation for a non-descending sequence, 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.
Screenshot of New Ket network problem:
The subject itself is very good, is a non-descending array (let's think of it as an incremental array of good) in front of the section and put it to the front (of course, you can not cut, that is, the length of the section is 0, and then run, loop, and judge the number of the first one larger than it and the latter one smaller than it, this number is the minimum number of the original series , which is the place where the previous position is grafted up after the back section is truncated. And then you're smart. Through the analysis will find that, as long as some simple pretreatment, you can greatly simplify the judgment conditions, of course, the conditions of their own judgment is not very complicated. Answer:
Import java.util.ArrayList;
public class Solution {public
int minnumberinrotatearray (int [] array) {
if (array==null| | Array.length==0) return 0;
if (Array.Length ==1) return array[0];
for (int j = 1;j<array.length; j + +) {
if (Array[j]<array[j-1]) {return
array[j];
}
}
return array[0];
}
New Ket Network compiled by screenshot: