Python offer minimum number of wins the rotation of the array

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

After the first rotation of the array is incremented, and then suddenly the fault, and then make incremental, so long suddenly find an array of smaller numbers that can be.

Code

# -*- coding:utf-8 -*-
class Solution:
    def minNumberInRotateArray(self, rotateArray):
        if rotateArray is None:
            return None
        temp = rotateArray[0]
        for i in range(len(rotateArray) - 1):
            if rotateArray[i] > rotateArray[i+1]:
                temp = rotateArray[i+1]
                break
        return temp

  

Guess you like

Origin www.cnblogs.com/wangzhihang/p/11781065.html