题目标签:Sort
遍历array 的过程中,找出min 和 max, 最后用 sum - min - max 来求得平均数。
具体看code。
Java Solution:
Runtime: 0 ms, faster than 100.00%
Memory Usage: 37.3 MB, less than 51.17 %
完成日期:9/7/2020
关键点:sum - min - max
class Solution { public double average(int[] salary) { double min = salary[0]; double max = salary[0]; double sum = 0; for(int s : salary) { min = Math.min(s, min); max = Math.max(s, max); sum += s; } return (sum - min - max) / (salary.length - 2); } }
LeetCode 题目列表 - LeetCode Questions List
题目来源:https://leetcode.com/