← 返回 doordash 的题目列表Find the Peak Element
类型:online_judge
Given an integer array nums where nums[i] != nums[i + 1] for all valid i, find a peak element and return its index. The array may contain multiple peaks, in that case, return any of them. Implement a function that finds the peak in O(logN) time complexity.
Test cases:
Input: nums = [1, 2, 3, 1]
Output: 2
Input: nums = [1, 2, 1, 3, 5, 6, 4]
Output: 5
Constraints:
1 <= nums.length <= 1000
-2^31 <= nums[i] <= 2^31 - 1
nums[i] != nums[i + 1] for all valid i
Example
Input
[1, 2, 3, 1]