The smallest number of offer--rotating arrays

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.