Find Peak Element

A peak element in a 0-indexed integer array is one that is strictly greater than its neighbors. The task is to find such a peak element and return its index. If multiple peaks exist, any of them can be returned. The array is considered to have virtual elements with negative infinity at its two ends for comparison purposes. The solution must be optimized to run in logarithmic time complexity, O(log n).

Constraints

  • 1 <= nums.length <= 1000
  • -2^31 <= nums[i] <= 2^31 - 1
  • nums[i] != nums[i + 1] for all valid i
Saving… · 2 lines
class Solution:
def findPeakElement(self, nums: List[int]) -> int:
Console

Click Run to execute sample tests.