1491. 去掉最低工资和最高工资后的工资平均值

去掉最低工资和最高工资后的工资平均值

解法一: 循环

go
1
2
3
4
5
6
7
8
9
10
11
func average(salary []int) float64 {
minSalary := math.MaxInt
maxSalary := math.MinInt
sum := 0
for _, num := range salary {
sum += num
minSalary = min(minSalary, num)
maxSalary = max(maxSalary, num)
}
return float64(sum-minSalary-maxSalary) / float64(len(salary)-2)
}
作者

wuhunyu

发布于

2024-05-03

更新于

2025-01-15

许可协议