Hard-题目5:154. Find Minimum in Rotated Sorted Array II

题目原文:
Suppose a sorted array is rotated at some pivot unknown to you beforehand.

(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).

Find the minimum element.

The array may contain duplicates.
题目大意:
对一个移位后的排序数组(可能存在重复数字)求最小元素。
题目分析:
从头扫一遍即可。也可以通过找跳转点(从最大值突变到最小值,期望是暴力枚举法的1/2)
源码:(language:java)

public class Solution {
    public int findMin(int[] nums) {
        int min = Integer.MAX_VALUE;
        for(int num : nums)
            min=Math.min(num,min);
        return min;
    }
}

成绩:
1ms,beats 5.33%,众数1ms,94.67%

你可能感兴趣的:(Hard-题目5:154. Find Minimum in Rotated Sorted Array II)