My simple Python solution


  • 0
    F
    class Solution:
    # @param nums, an integer[]
    # @return an integer
    def findPeakElement(self, nums):
        if len(nums)==1:
            return 0
        x=0
        while(x<len(nums)):
            if (x==0 and nums[x]>nums[x+1]) or (x==len(nums)-1 and nums[x]>nums[x-1]) or (nums[x]>nums[x-  1] and nums[x]>nums[x+1]):
                return x
            x+=1

Log in to reply
 

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