数组旋转

把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转。

输入一个非递减排序的数组的一个旋转,输出旋转数组的最小元素。

import java.util.*;
public class Solution {
public int minNumberInRotateArray(int[] array) {
        for (int j = 0;j < array.length; j++) {
            if (array[j+1] < array[j]) {
                return array[j+1];
            }
        }
        return 0;
    }
}

猜你喜欢

转载自blog.csdn.net/quitozang/article/details/80456465
今日推荐