Moves the first element 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.
This is to look for the smallest value in the array, but if the first one like the following, although the function can be implemented, but in the field of hand-torn code when the offer is certainly not
class Solution: def Minnumberinrotatearray (Self, Rotatearray): # Write code here if not Rotatearray: return 0 Else : return min (rotatearray)
classSolution:defMinnumberinrotatearray (Self, rotatearray):#Write code here " "consider three scenarios: 1. The array is an empty array, at which time the return value is 0 2. There is only one element in the array, so the minimum value is the element 3 when there is no comparison. More than 1 elements in the array" " if(rotatearray==[]): return0 I=0if(I==len (Rotatearray)-1): returnRotatearray[0]" "considering that the array itself is non-descending, it is conceivable that the rotation array contains two sub-arrays, the sub-array itself is ordered, as long as the vector two elements are compared between, if the former is greater than the latter, then this is the two sub-array of the demarcation point, such as [3,4,5,1,2], containing two ordered sub-arrays [ 3,4,5] and [all], the sub-array itself is not decremented, then find the inflection point, is the smallest element inside the array" " while(I<len (Rotatearray)-1): if(rotatearray[i]<=rotatearray[i+1]): I+=1Else: returnROTATEARRAY[I+1]
The smallest number of offer--rotating arrays