Suppose an array of length n sorted in ascending order is rotated between 1 and n times. Given the rotated array, find the minimum element. All elements are unique.
Binary search: if nums[mid] > nums[hi], the minimum is in the right half. Otherwise it is in the left half (including mid).
- While lo < hi:
- mid = lo + (hi-lo)/2.
- If nums[mid] > nums[hi]: minimum must be in right half, lo = mid+1.
- Else: minimum is in left half (possibly mid), hi = mid.
- Return nums[lo].
- Time Complexity: O(log N)
- Space Complexity: O(1)