Find Minimum in Rotated Sorted Array

原创 2015年07月07日 10:29:56
//逻辑是否可以再清晰些。
public class Solution {
    public int findMin(int[] nums) {
        if (nums == null || nums.length == 0) {
            return Integer.MIN_VALUE;
        }
        int left = 0;
        int right = nums.length - 1;
        while (left < right) {
            if (nums[left] < nums[right]) {
                return nums[left];
            }
            int mid = left + (right - left) / 2;
            if (mid != 0 && nums[mid] < nums[mid - 1]) {
                return nums[mid];
            }
            if (nums[mid] >= nums[left]) {
                left = mid + 1;
            } else {
                right = mid;
            }
        }
        return nums[left];
    }
}

相关文章推荐

【LeetCode-面试算法经典-Java实现】【154-Find Minimum in Rotated Sorted Array II(找旋转数组中的最小数字II)】

【154-Find Minimum in Rotated Sorted Array II(找旋转数组中的最小数字II)】【LeetCode-面试算法经典-Java实现】【所有题目目录索引】原题  Fo...

leetcode解题之153&154. Find Minimum in Rotated Sorted Array版(在旋转的数组中查找最小数字)

leetcode解题之153&154. Find Minimum in Rotated Sorted Array版(在旋转的数组中查找最小数字)...

LeetCode Solutions : Find Minimum in Rotated Sorted Array

【算法思路】利用折半查找的思路去查找这个最小元素 【编程步骤】 * 1. 如果数组num只有一个元素,则所求的最小的元素就是它了; * 2. 若left到right位置的元素严格递增,则最小的元素...
  • lviiii
  • lviiii
  • 2015年01月07日 15:35
  • 696

[leetcode] 154.Find Minimum in Rotated Sorted Array II

题目: Follow up for “Find Minimum in Rotated Sorted Array”: What if duplicates are allowed?Would thi...

153. Find Minimum in Rotated Sorted Array\229. Majority Element II\Moore's voting algorithm

Find Minimum in Rotated Sorted Array 题目描述 代码实现153. Find Minimum in Rotated Sorted Array题目描述一个已经排好序的数...

Leetcode 153. Find Minimum in Rotated Sorted Array

Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e.,...

※ Leetcode - Binary Search - 153. Find Minimum in Rotated Sorted Array(二分查找)

1. Problem Description Suppose a sorted array is rotated at some pivot unknown to you beforehand.   ...

【leetcode】Find Minimum in Rotated Sorted Array

一、问题描述 Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1...

[leetcode 153]Find Minimum in Rotated Sorted Array----求旋转数组的最小值

Question: Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., ...

leetcode之Find Minimum in Rotated Sorted Array

Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 m...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Find Minimum in Rotated Sorted Array
举报原因:
原因补充:

(最多只允许输入30个字)