mediumBinary Search Pattern
Find Peak Element
A peak element is an element that is strictly greater than its neighbors. Given an integer array `nums`, find a peak element, and return its index. If the array contains multiple peaks, return the index to any of the peaks. You must write an algorithm that runs in O(log n) time.
Examples
Input:
nums = [1,2,3,1]Output:
2Explanation: 3 is a peak element and your function should return index 2.
Hints (0/2)
Try to solve it first! Click "Reveal Next Hint" if you get stuck.
Your Code:
Results:
Output
Click "Run" to execute your code