1491. Average Salary Excluding the Minimum and Maximum Salary

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)
            

 

posted @ 2020-06-29 13:11  whatyouthink  阅读(63)  评论(0编辑  收藏  举报