153. Find Minimum in Rotated Sorted Array - LeetCode

Posted okokabcd

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了153. Find Minimum in Rotated Sorted Array - LeetCode相关的知识,希望对你有一定的参考价值。

Question

153.?Find Minimum in Rotated Sorted Array

技术分享图片

Solution

题目大意:给一个按增序排列的数组,其中有一段错位了[1,2,3,4,5,6]变成[4,5,6,1,2,3],把1求出来

思路:遍历,如果当前元素比前一个元素小就是这个元素了

Java实现:

public int findMin(int[] nums) {
    int ans = nums[0];
    for (int i=0; i<nums.length; i++) {
        int pre = i==0?nums[0]:nums[i-1];
        if (nums[i] < pre) {
            ans = nums[i];
            break;
        }
    }
    return ans;
}

以上是关于153. Find Minimum in Rotated Sorted Array - LeetCode的主要内容,如果未能解决你的问题,请参考以下文章

153. Find Minimum in Rotated Sorted Array

#Leetcode# 153. Find Minimum in Rotated Sorted Array

153. Find Minimum in Rotated Sorted Array

153. Find Minimum in Rotated Sorted Array

153 Find Minimum in Rotated Sorted Array

153. Find Minimum in Rotated Sorted Array