2951. Find the Peaks

1
2
3
4
5
6
7
8
9
10
11
12
13
class Solution {
public List<Integer> findPeaks(int[] mountain) {
List<Integer> resultList = new ArrayList<>();

for (int i = 1; i < mountain.length - 1; i++) {
if (mountain[i] > mountain[i - 1] && mountain[i] > mountain[i + 1]) {
resultList.add(i); // 注意题目要求返回下标
}
}

return resultList;
}
}

References

2951. Find the Peaks