Skip to content

#162 - Find Peak Element

MediumBinary Search
Open on LeetCode

A peak element is strictly greater than its neighbors. Given an integer array nums where nums[i] ≠ nums[i + 1], find any peak element and return its index. The array may contain multiple peaks. You must solve in O(log n) time. Assume nums[-1] = nums[n] = -∞.

InputOutput
nums = [1,2,3,1]2
nums = [1,2,1,3,5,6,4]5 (or 1)

Released under the MIT License.