Average Salary Excluding the Minimum and Maximum Salary
给一个数组, 里面是salary, 求除了最大和最小数的salary的平均数.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
class Solution { public double average(int[] salary) { int max = 0; int min = Integer.MAX_VALUE; double total = 0d; for(int s : salary) { max = Math.max(max, s); min = Math.min(min, s); total += s; } return (total - min - max) / (salary.length - 2); } } |