LeetCode solutions

3221. Find the Peaks

My accepted JavaScript solution to LeetCode problem 3221, Find the Peaks, running in 0ms.

  • Difficulty: Easy
  • JavaScript
  • Runtime 0ms
  • Memory 57.1MB

Read the problem on LeetCode View on GitHub

JavaScript

Accepted on LeetCode — runtime 0ms, memory 57.1MB, accepted 2025-12-29.

javascript
/**
* @param {number[]} mountain
* @return {number[]}
*/
var findPeaks = function(mountain) {
    const result = [];
    for (let i = 1; i < mountain.length - 1; i++) {
        if (mountain[i] > mountain[i-1] && mountain[i] > mountain[i+1]) {
            result.push(i);
        }
    }
    return result;
};

Source