Find the Smallest Element After a Sorted Array Is Rotated
Implement findMin
An array of unique values, sorted in ascending order, is rotated at some unknown pivot — for example
[0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2]. Given the rotated array nums, return its smallest element.
Solve it in O(log n) time by binary-searching for the "seam" where the array's values drop from high back down to low.
Example 1:
Input: nums = [4,5,6,7,0,1,2]
Output: 0
Example 2:
Input: nums = [3,4,5,1,2]
Output: 1
Example 3:
Input: nums = [11,13,15,17]
Output: 11
+ 4 hidden test cases run on Submit.
Constraints:
- ●
1 ≤ nums.length ≤ 5000 - ●
-5000 ≤ nums[i] ≤ 5000 - ●
All the values of nums are unique - ●
nums was sorted in ascending order, then possibly rotated
nums =
[4, 5, 6, 7, 0, 1, 2]