Skip to content
LC-2951 Easy LeetCode

2951. Find the Peaks

Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 74% Topics: Array, Enumeration
View full problem on LeetCode
Reference solution (spoiler · python)
# Time:  O(n)
# Space: O(1)

# array
class Solution(object):
    def findPeaks(self, mountain):
        """
        :type mountain: List[int]
        :rtype: List[int]
        """
        return [i for i in xrange(1, len(mountain)-1) if mountain[i-1] < mountain[i] > mountain[i+1]]

Solution from kamyu104/LeetCode-Solutions · MIT