LeetCode Brushing Questions 1491. Average wage after removing minimum wage and maximum wage

LeetCode Brushing Questions 1491. Average wage after removing minimum wage and maximum wage

I don't know where I am going, but I am already on my way!
Time is hurried, although I have never met, but I met Yusi, it is really a great fate, thank you for your visit!
  • Topic :
    give you an array of integers salary, each number in the array is unique, which salary[i]is the first iemployees of wages.
    Please return the average wages of employees after removing the minimum and maximum wages.
  • Example :
示例 1 :
输入:salary = [4000,3000,1000,2000]
输出:2500.00000
解释:最低工资和最高工资分别是 1000 和 4000 。
去掉最低工资和最高工资以后的平均工资是 (2000+3000)/2= 2500
示例 2 :
输入:salary = [1000,2000,3000]
输出:2000.00000
解释:最低工资和最高工资分别是 1000 和 3000 。
去掉最低工资和最高工资以后的平均工资是 (2000)/1= 2000
示例 3 :
输入:salary = [6000,5000,4000,3000,2000,1000]
输出:3500.00000
示例 4 :
输入:salary = [8000,9000,2000,3000,6000,1000]
输出:4750.00000
  • Tips :
    • 3 <= salary.length <= 100
    • 10^3 <= salary[i] <= 10^6
    • salary[i] only one.
    • And the real value of the error in 10^-5the results will be considered within the correct answer.
  • Code 1:
class Solution:
    def average(self, salary: List[int]) -> float:
        salary.sort()
        return sum(salary[1:-1]) / (len(salary)-2)
# 执行用时:36 ms, 在所有 Python3 提交中击败了83.74%的用户
# 内存消耗:13.7 MB, 在所有 Python3 提交中击败了100.00%的用户
  • Algorithm description:
    Sort the array first, remove the maximum and minimum values, and then average.

Guess you like

Origin blog.csdn.net/qq_34331113/article/details/107094908