> For the complete documentation index, see [llms.txt](https://blessbingo.gitbook.io/garnet/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://blessbingo.gitbook.io/garnet/suan-fa/er-fen/153-xun-zhao-xuan-zhuan-pai-xu-shu-zu-zhong-de-zui-xiao-zhi.md).

# \[153]\[中等]\[二分] 寻找旋转排序数组中的最小值

## 题目描述

[153. 寻找旋转排序数组中的最小值](https://leetcode-cn.com/problems/find-minimum-in-rotated-sorted-array/)

假设按照升序排序的数组在预先未知的某个点上进行了旋转。

( 例如，数组 \[0,1,2,4,5,6,7] 可能变为 \[4,5,6,7,0,1,2] )。

请找出其中最小的元素。

你可以假设数组中不存在重复元素。

示例 1:

```
输入: [3,4,5,1,2]
输出: 1
```

示例 2:

```
输入: [4,5,6,7,0,1,2]
输出: 0
```

## 解题思路

二分法找到最小的那个元素. 因为**不存在重复元素**, 所以两两之间互不相等, 一定有大小之分. 开始将左右指针放在第一个会最后一个元素上, 求得中间值, 将中间值与右端的值相比, 如果中间值更小, 说明中间和右端之间是递增的, 最小值不在右半边, 将右端移动到中间位置; 如果中间值更大, 最小值就在右半边, 将左端移动到中间位置. 但考虑到左端可能与中间位置重叠, 以及中间值大于右端值, 也肯定大于最小值, 所以中间值肯定不是最小值, 需要将左端移动到`mid + 1`的位置.

代码如下:

```python
class Solution:
    def findMin(self, nums: List[int]) -> int:
        n = len(nums)
        left, right = 0, n - 1
        while left < right:
            mid = (left + right) // 2
            if nums[mid] > nums[right]:
                left = mid + 1
            else:
                right = mid
        return nums[left]
```

## 相关题目

* [\[154\]\[困难\]\[二分\] 寻找旋转排序数组中的最小值 II](/garnet/suan-fa/er-fen/154-xun-zhao-xuan-zhuan-pai-xu-shu-zu-zhong-de-zui-xiao-zhi-ii.md)
* [\[剑指Offer-11\]\[简单\]\[二分\] 旋转数组的最小数字](/garnet/suan-fa/er-fen/jian-zhi-offer11-xuan-zhuan-shu-zu-de-zui-xiao-shu-zi.md)
