2951. 找出峰值

找出峰值

解法一: 循环

go
1
2
3
4
5
6
7
8
9
10
11
func findPeaks(mountain []int) []int {
ans := []int{}
n := len(mountain)
for i := 1; i < n-1; i++ {
if mountain[i] > mountain[i-1] && mountain[i] > mountain[i+1] {
ans = append(ans, i)
i++
}
}
return ans
}
作者

wuhunyu

发布于

2024-05-28

更新于

2025-01-15

许可协议