We’re preparing your current view and syncing the latest data.
Suppose an array of length n sorted in ascending order is rotated between 1 and n times. Given the rotated array nums of unique elements, return the minimum element of this array. You must write an algorithm that runs in O(log n) time.
An integer array nums representing a rotated sorted array with unique elements.
Return an integer representing the minimum element in the array.
1 <= nums.length <= 5000; -10^4 <= nums[i] <= 10^4; All integers of nums are unique.
Example 1
Input
[3,4,5,1,2]
Output
1
Explanation
The original sorted array was [1,2,3,4,5] and it was rotated 3 times. The minimum element is 1.
Example 2
Input
[4,5,6,7,0,1,2]
Output
0
Explanation
The original sorted array was [0,1,2,4,5,6,7] rotated 4 times. The minimum element is 0.
Example 3
Input
[11,13,15,17]
Output
11
Explanation
The array is not rotated, so the minimum element is the first element 11.