当前位置:网站首页>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);
}
边栏推荐
- "Remake Apple product UI with Android" (2) -- silky Appstore card transition animation
- WinDbg analysis dump file
- Brush questions -- sword finger offer
- 切入点表达式
- Microservice API gateway zuul
- Mixlab编辑团队招募队友啦~~
- First knowledge of database
- Remote file contains actual operation
- Reflection on some things
- The difference between RAR and zip files
猜你喜欢
Microservice - declarative interface call openfeign
Remote file contains actual operation
Unityshader - materialcapture material capture effect (Emerald axe)
Wechat payment -jsapi: code implementation (payment asynchronous callback, Chinese parameter solution)
Embedded development: seven reasons to avoid open source software
App mobile terminal test [5] file writing and reading
【Proteus仿真】74HC595+74LS154驱动显示16X16点阵
"Remake Apple product UI with Android" (3) - elegant statistical chart
Slam learning notes - build a complete gazebo multi machine simulation slam from scratch (II)
Slam learning notes - build a complete gazebo multi machine simulation slam from scratch (4)
随机推荐
Go语言自学系列 | golang switch语句
Famous blackmail software stops operation and releases decryption keys. Most hospital IOT devices have security vulnerabilities | global network security hotspot on February 14
使用AUR下载并安装常用程序
首发!!lancet饿了么官方文档
Persisting in output requires continuous learning
Expression of request header in different countries and languages
Driver and application communication
用通达信炒股开户安全吗?
[list to map] collectors Tomap syntax sharing (case practice)
Principles of several common IO models
【Proteus仿真】74HC595+74LS154驱动显示16X16点阵
坚持输出需要不断学习
A Fei's expectation
The mixlab editing team is recruiting teammates~~
利用MySQL中的乐观锁和悲观锁实现分布式锁
Low level version of drawing interface (explain each step in detail)
Remote file contains actual operation
几种常见IO模型的原理
Backtracking method to solve batch job scheduling problem
Shell script import and export data