Find a Peak Element
Return the index of any value that is bigger than both of its neighbors.
The problem
Implement Solution.findPeakElement(nums). nums holds between 1 and 1,000 integers, and no two neighbors are equal. A peak is a value strictly bigger than its neighbors; pretend the values just outside the list are negative infinity, so the first and last values only need to beat their one real neighbor. Return the index of any peak. Your solution must run in O(log n) time.
Starter code
class Solution:
def findPeakElement(self, nums):
passPublic examples
nums = [1, 2, 3, 1]gives2nums = [-3]gives0nums = [1, 3, 5, 7, 9, 6, 2]gives4
Solving it in the practice book needs an active paid plan.
Open it in the practice bookOne thought at a time.
