Find Peak Element

Problem Id: 162 Difficulty: Medium


Intuition

Solution


class Solution:
    def findPeakElement(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        for i in range(len(nums)):
            if i > 0 and nums[i] <= nums[i-1]:
                continue
            if i < len(nums) - 1 and nums[i] <= nums[i+1]:
                continue
            return i