Simpe O(N) solution


  • 0
    A

    """

    def findPeakElement(self, nums):
        l = len(nums)
        if l == 1:
            return 0
        if nums[0] > nums[1]:
            return 0
        elif nums[l-1] > nums[l-2]:
            return l-1
        for i in range(1,l-1):
            if nums[i] > nums[i-1] and nums[i] > nums[i+1]:
                return i
        return -1
    

    """


Log in to reply
 

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