#154
Find Minimum in Rotated Sorted Array II
candidate master · 1575 · lc hard +32 · verified · 44.7% accepted · 5,068 likes · top 27%
Description
A sorted array of length n (which may contain duplicates) has been rotated between 1 and n times. For example, the array nums = [0,1,4,4,5,6,7] might become:
- [4,5,6,7,0,1,4] after 4 rotations.
- [0,1,4,4,5,6,7] after 7 rotations.
Rotating [a[0], a[1], a[2], ..., a[n-1]] once gives [a[n-1], a[0], a[1], a[2], ..., a[n-2]].
Given the rotated array nums that may contain duplicates, return its minimum element. Minimize the total number of operations.
Example 1:
Input: nums = [1,3,5]
Output: 1
Example 2:
Input: nums = [2,2,2,0,1]
Output: 0
Code
1
2
3