剑指Office-旋转数组的最小数

时间:2022-07-22
本文章向大家介绍剑指Office-旋转数组的最小数,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

旋转数组的最小数字

题目

//把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转。输入一个递增排序的数组的一个旋转,输出旋转数组的最小元素。例如,数组 [3,4,5,1,2
//] 为 [1,2,3,4,5] 的一个旋转,该数组的最小值为1。 
//
// 示例 1: 
//
// 输入:[3,4,5,1,2]
//输出:1
// 
//
// 示例 2: 
//
// 输入:[2,2,2,0,1]
//输出:0
// 
//
// 注意:本题与主站 154 题相同:https://leetcode-cn.com/problems/find-minimum-in-rotated-sor
//ted-array-ii/ 
// Related Topics 二分查找


//leetcode submit region begin(Prohibit modification and deletion)
class Solution {
    public int minArray(int[] numbers) {

    }
}
//leetcode submit region end(Prohibit modification and deletion)

最简单的写法:

class Solution {
    public int minArray(int[] numbers) {
        Arrays.sort(numbers);
        return numbers[0];
    }
}

结果: