# 153. 寻找旋转排序数组中的最小值(二分查找)(153. Find the minimum value in the rotation sort array (binary search))-其他

## 153. 寻找旋转排序数组中的最小值(二分查找)(153. Find the minimum value in the rotation sort array (binary search))

### 153. 寻找旋转排序数组中的最小值

``n``
``1``
``n``
``nums = [0,1,2,4,5,6,7]``
• 若旋转 4 次，则可以得到 [4,5,6,7,0,1,2]
• 若旋转 7 次，则可以得到 [0,1,2,4,5,6,7]

``[a[0], a[1], a[2], ..., a[n-1]]``
``[a[n-1], a[0], a[1], a[2], ..., a[n-2]]``

``nums``

``O(log n)``

``````输入：nums = [3,4,5,1,2]

``````

``````输入：nums = [4,5,6,7,0,1,2]

``````

``````输入：nums = [11,13,15,17]

``````

• n == nums.length
• 1 <= n <= 5000
• -5000 <= nums[i] <= 5000
• nums 中的所有整数 互不相同
• nums 原来是一个升序排序的数组，并进行了 1 至 n 次旋转
`````` 1 class Solution {
2 public:
3     int findMin(vector<int>& nums) {
4         int left = 0;
5         int right = nums.size() - 1;
6         while (left < right) {
7             int mid = left + (right - left) / 2;
8             if (nums[mid] < nums[right]) { // 最小值在左边
9                 right = mid;
10             } else { // 最小值在右边
11                 left = mid + 1;
12             }
13         }
14         return nums[left];
15     }
16 };``````
————————

### 153. Find the minimum value in the rotation sort array

``n``
``1``
``n``
``nums = [0,1,2,4,5,6,7]``
• If you rotate it four times, you can get [4,5,6,7,0,1,2]
• If you rotate it seven times, you can get [0,1,2,4,5,6,7]

Note that the array ， is rotated once, and the result of ， is an array.

``[a[0], a[1], a[2], ..., a[n-1]]``
``[a[n-1], a[0], a[1], a[2], ..., a[n-2]]``

Give you an array with element values ， which are different from each other. It was originally an array arranged in ascending order and rotated many times according to the above situation. Please find and return the smallest element in the array.

``nums``

You must design an algorithm with a time complexity of {to solve this problem.

``O(log n)``

Example 1:

``````输入：nums = [3,4,5,1,2]

``````

Example 2:

``````输入：nums = [4,5,6,7,0,1,2]

``````

Example 3:

``````输入：nums = [11,13,15,17]

``````

Tips:

• n == nums.length
• 1 <= n <= 5000
• -5000 <= nums[i] <= 5000
• All integers ， in num ， are different from each other
• Num s ， was originally an array sorted in ascending order and rotated ， 1 ， to ， n ， times
`````` 1 class Solution {
2 public:
3     int findMin(vector<int>& nums) {
4         int left = 0;
5         int right = nums.size() - 1;
6         while (left < right) {
7             int mid = left + (right - left) / 2;
8             if (nums[mid] < nums[right]) { // 最小值在左边
9                 right = mid;
10             } else { // 最小值在右边
11                 left = mid + 1;
12             }
13         }
14         return nums[left];
15     }
16 };``````