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
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
JavaScript
Accepted on LeetCode — runtime 0ms, memory 57.1MB, accepted 2025-12-29.
/**
* @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;
};