Two lines brute force search

  • 1

    I add -infinity to the end of nums in order to avoid all boundary checks.
    Then I simply find the first element which is bigger than its next one.

    def findPeakElement(self, nums):
        return next(i for i in range(len(nums) - 1) if nums[i] > nums[i + 1])

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.