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%

阅读更多
版权声明:完整版Leetcode题解请出门左转https://github.com/cmershen1/leetcode/tree/master/docs https://blog.csdn.net/cmershen/article/details/51550164
个人分类: Leetcode
上一篇Hard-题目4:145. Binary Tree Postorder Traversal
下一篇Hard-题目6:117. Populating Next Right Pointers in Each Node II
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭