Sword Point offer Java-Find the smallest number of rotated arrays

Source: Internet
Author: User

/**
* Created by WQC on 2017/7/18.
* Find the smallest number of rotated arrays
* Move a number of elements at the beginning of an array to the end of the array, called the rotation of the array
* Enter a rotation of an incrementally sorted array, output the smallest element of the rotated array
* For example: 3,4,5,1,2 is a rotation of 1,2,3,4,5, the minimum value is 1
*/
public class Problem8_findminnumber {
Public Integer Findminnum (int[] array)
{
if (array = = NULL)
{
return null;
}

int leftindex = 0;
int Rightindex =array.length-1;
int mid = 0;
while (Array[leftindex]>=array[rightindex])
{
if (Rightindex-leftindex <= 1)
{
MID = Rightindex;
Break
}

Mid = (Leftindex + rightindex)/2;
if (array[leftindex] = = Array[rightindex] && Array[leftindex] = = Array[mid])
{
if (Array[leftindex + 1]! = Array[rightindex-1])
{
MID = Array[leftindex + 1] < array[rightindex-1]? (Leftindex + 1): (rightIndex-1);
Break
}else{
leftindex++;
rightindex--;
}
}else if (Array[mid] >= Array[leftindex]) {

Leftindex = mid;
}else if (Array[mid] <= Array[rightindex]) {

Rightindex = mid;
}
}
return Array[mid];
}

}

Sword refers to offer Java-find the smallest number of rotated 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.