AC Python solution, easy to understand, just find the max and return the index


  • 0
    W

    class Solution(object):

    def findPeakElement(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        numLen = len(nums)
        #print "numLen = ", numLen
    
        res = 0
        
        if (numLen == 1):
            return 0
        
        for i in range (numLen-1):
            if (nums[i+1] > nums[i]):
                res = i+1
                
        return res

Log in to reply
 

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