問題
原文
You are given an array of unique integers
salary
wheresalary[i]
is the salary of theith
employee.Return the average salary of employees excluding the minimum and maximum salary. Answers within
10-5
of the actual answer will be accepted.
Example 1:
1234 Input: salary = [4000,3000,1000,2000]Output: 2500.00000Explanation: Minimum salary and maximum salary are 1000 and 4000 respectively.Average salary excluding minimum and maximum salary is (2000+3000) / 2 = 2500Example 2:
1234 Input: salary = [1000,2000,3000]Output: 2000.00000Explanation: Minimum salary and maximum salary are 1000 and 3000 respectively.Average salary excluding minimum and maximum salary is (2000) / 1 = 2000
Constraints:
3 <= salary.length <= 100
1000 <= salary[i] <= 106
- All the integers of
salary
are unique.
内容
i番目の要素がi番目の従業員の給料を示す、各要素が相異なる整数を持つリストsalaryが与えられます。
最大値と最小値を除いた給料の平均値を返してください。
解答は10^(-5)以内の誤差とします。
※正しくない可能性があります。
解答
解答1:Python
1 2 3 4 5 6 7 8 9 10 11 12 |
class Solution: def average(self, salary: List[int]) -> float: #salaryを並び替え salary.sort() #最初と最後(最小値と最大値)を除いたリストに変換 salary = salary[1:-1] #salaryの合計値を求める sum_of_salary = sum(salary) #salaryの平均値を求める mean_of_salary = sum_of_salary/len(salary) #salaryの平均値を返す return mean_of_salary |
解答2:
メモ・参考・感想
前:1523. Count Odd Numbers in an Interval Range
コメント