Given an array of unique integers salary
where salary[i]
is the salary of the employee i
.
Return the average salary of employees excluding the minimum and maximum salary.
求(total - min -max) / (n - 2)
class Solution(object): def average(self, salary): """ :type salary: List[int] :rtype: float """ total = 0 max_value = salary[0] min_value = salary[0] for s in salary: total += s max_value = max(max_value, s) min_value = min(min_value, s) total = total - max_value - min_value return total / float(len(salary) - 2)