← 返回 meta 的题目列表Find a Local Minimum in an Array
类型:online_judge
Given an integer array nums in which adjacent elements are never equal, use an iterative binary search to return an index of any local minimum.
An index i is a local minimum if:
nums[i] < nums[i - 1], treating the left side as positive infinity when i = 0; and
nums[i] < nums[i + 1], treating the right side as positive infinity when i = n - 1.
Requirements:
Do not use recursion.
The time complexity must be O(log n).
Any valid local-minimum index may be returned.
Input Format
The first line is n; the second line contains the array values.
Example
Input
5
9 7 3 5 8
Output
2
Constraints
1 <= n <= 2 * 10^5
nums[i] != nums[i + 1].
Example
Input
5
9 7 3 5 8
Output
2