Find Peak Element

May 29, 2017


leetcode 162

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