当前位置:网站首页>LeetCode1491. Average value of wages after removing the minimum wage and the maximum wage
LeetCode1491. Average value of wages after removing the minimum wage and the maximum wage
2022-07-03 16:07:00 【what's your name.】
【 Simple 】 Give you an array of integers salary , Every number in the array is only Of , among salary[i] It's No i The salary of an employee .
Please go back and remove the minimum wage and the maximum wage , The average wage of the remaining employees .
Example 1:
Input :salary = [4000,3000,1000,2000]
Output :2500.00000
explain : The minimum wage and the maximum wage are respectively 1000 and 4000 .
The average wage after removing the minimum wage and the maximum wage is (2000+3000)/2= 2500
Example 2:
Input :salary = [1000,2000,3000]
Output :2000.00000
explain : The minimum wage and the maximum wage are respectively 1000 and 3000 .
The average wage after removing the minimum wage and the maximum wage is (2000)/1= 2000
Example 3:
Input :salary = [6000,5000,4000,3000,2000,1000]
Output :3500.00000
Example 4:
Input :salary = [8000,9000,2000,3000,6000,1000]
Output :4750.00000
Tips :
3 <= salary.length <= 100
10^3 <= salary[i] <= 10^6
salary[i] Is the only one. .
The error with the true value is within 10^-5 All the results within will be regarded as the correct answer .
Solution 1 :
double m1(int[] salary) {
Arrays.sort(salary);
int sum = 0;
for (int i = 1; i < salary.length-1; i++) {
sum += salary[i];
}
return (double) sum / (salary.length-2);
}
Solution 2 :
double m2(int[] salary) {
int max = salary[0];
int min = salary[0];
int sum = 0;
for (int i = 0; i < salary.length; i++) {
sum += salary[i];
if (salary[i] > max)
max = salary[i];
else if (salary[i] < min)
min = salary[i];
}
return (double) (sum-max-min) / (salary.length-2);
}
边栏推荐
- Microservices Seata distributed transactions
- pyinstaller不是内部或外部命令,也不是可运行的程序 或批处理文件
- [combinatorics] combinatorial identities (review of eight combinatorial identities | product of combinatorial identities 1 | proof | use scenario | general method for finding combinatorial numbers)
- 【OpenCV 例程200篇】217. 鼠标交互获取多边形区域(ROI)
- Unity function - unity offline document download and use
- [list to map] collectors Tomap syntax sharing (case practice)
- [combinatorics] combinatorial identity (sum of combinatorial identity products 1 | sum of products 1 proof | sum of combinatorial identity products 2 | sum of products 2 proof)
- Three dimensional reconstruction of deep learning
- App mobile terminal test [4] APK operation
- Redis高可用与持久化
猜你喜欢

Microservice sentinel flow control degradation

MB10M-ASEMI整流桥MB10M
![SDNU_ ACM_ ICPC_ 2022_ Winter_ Practice_ 4th [individual]](/img/3b/7523eca5bbcdbba29d9b7f6e4791a5.jpg)
SDNU_ ACM_ ICPC_ 2022_ Winter_ Practice_ 4th [individual]

The mixlab editing team is recruiting teammates~~

Asemi rectifier bridge umb10f parameters, umb10f specifications, umb10f package

Find mapping relationship

几种常见IO模型的原理

Microservice API gateway

Salary 3000, monthly income 40000 by "video editing": people who can make money never rely on hard work!

Distributed task scheduling XXL job
随机推荐
嵌入式开发:避免开源软件的7个理由
WinDbg analysis dump file
From the 18th line to the first line, the new story of the network security industry
EditText request focus - EditText request focus
June to - -------
Persisting in output requires continuous learning
Find mapping relationship
Microservice API gateway zuul
MongoDB 的安装和基本操作
Microservice - Nacos registration center and configuration center
深度学习之三维重建
pyinstaller不是内部或外部命令,也不是可运行的程序 或批处理文件
Approval process design
First!! Is lancet hungry? Official documents
Detailed explanation of four modes of distributed transaction (Seata)
Semi supervised learning
[系统安全] 四十三.Powershell恶意代码检测系列 (5)抽象语法树自动提取万字详解
[system safety] 43 PowerShell malicious code detection series (5) automatic extraction of ten thousand words from abstract syntax tree
Srs4.0+obs studio+vlc3 (environment construction and basic use demonstration)
Reading notes of "micro service design" (Part 2)