The minimum number of rotation of the array prove safety offer- - array -python

Title Description

The beginning of an array of several elements moved to the end of the array, the array we call rotation.
A non-descending order of the input array of a rotation of the output rotary smallest element array.
For example, an array {3,4,5,1,2} {1,2,3,4,5} is a rotation of the array to a minimum.
NOTE: All the elements are given in greater than 0, if the array size is 0, return 0.
 
Thinking
Know the meaning of the questions, after rotation, the output of the smallest element, then we can use min ().
When NA min () using a binary search.
 
Links: HTTPS: //www.nowcoder.com/questionTerminal/9f3231a991af4f55b95579b44b7a01ba f =? The Discussion 
Source: cattle off net 

# - * - Coding: UTF-8 - * - 
class Solution:
     DEF minNumberInRotateArray (Self, rotateArray):
         # can use min () function, but in the case of NA min function, the idea should be binary search 
        # using recursive look for the following two points, which must be used when the recursive return! ! ! Otherwise returns none 
        # Write code here Wallpaper 
        Start = 0 
        End = len (rotateArray) -. 1 
        MID = int ((Start + End) / 2 )
         IF len (rotateArray) == 2 :
             IF rotateArray [0]> rotateArray [. 1 ] :
                return rotateArray[1]
            else:
                return rotateArray[0]
 
        elif rotateArray[mid] > rotateArray[end]:
            return self.minNumberInRotateArray(rotateArray[mid:end + 1])
        elif rotateArray[mid] < rotateArray[start]:
            return self.minNumberInRotateArray(rotateArray[start:mid + 1])

 

Guess you like

Origin www.cnblogs.com/ansang/p/12033579.html