1. Drawing, intuitive.
2. The discussion array is empty or the number is zero.
3. Discussion of the first and the end, if the flip over the search until the last two numbers to compare, take the small one.
Public classSolution {/** * @paramnum:a rotated sorted array *@return: The minimum number in the array*/ Public intFindmin (int[] num) { //Write your code here if(num = =NULL|| Num.length = = 0)return-1; //int small = num[0]; //for (int i = 1; i < num.length; i++) {// //small = (Small < num[i])? Small:num[i]; //if (Small > num[i]) small = num[i]; //Else small = small; // } //return small; intleft = 0;intright = Num.length-1; if(Num[left] < num[right])returnNum[left]; Else{ while(Left + 1 <Right ) { intMid = (left + right)/2; if(Num[left] <Num[mid]) { Left=mid; } if(Num[left] >Num[mid]) { Right=mid; } } if(Num[left] < num[right])returnNum[left]; Else returnNum[right]; } }}
Lintcode Find Minimum in rotated Sorted Array