当前位置:网站首页>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);
}
边栏推荐
- EditText request focus - EditText request focus
- Go语言自学系列 | golang中的if else语句
- Jmeter线程组功能介绍
- Using optimistic lock and pessimistic lock in MySQL to realize distributed lock
- Vs2017 is driven by IP debugging (dual machine debugging)
- Redis high availability and persistence
- The accept attribute of the El upload upload component restricts the file type (detailed explanation of the case)
- App mobile terminal test [5] file writing and reading
- Driver and application communication
- App mobile terminal test [4] APK operation
猜你喜欢

2022年Q2加密市场投融资报告:GameFi成为投资关键词

Srs4.0+obs studio+vlc3 (environment construction and basic use demonstration)

Intelij idea efficient skills (III)

Project -- high concurrency memory pool

How to use AAB to APK and APK to AAB of Google play apps on the shelves

nifi从入门到实战(保姆级教程)——flow

Microservice API gateway zuul

近视:摘镜or配镜?这些问题必须先了解清楚

Getting started with Message Oriented Middleware

Detailed explanation of string function and string function with unlimited length
随机推荐
初试scikit-learn库
Nifi from introduction to practice (nanny level tutorial) - flow
Slam learning notes - build a complete gazebo multi machine simulation slam from scratch (4)
Persisting in output requires continuous learning
Wechat payment -jsapi: code implementation (payment asynchronous callback, Chinese parameter solution)
[redis foundation] understand redis master-slave architecture, sentinel mode and cluster together (Demo detailed explanation)
Unity function - unity offline document download and use
Calibre LVL
From "zero sum game" to "positive sum game", PAAS triggered the third wave of cloud computing
Redis在Windows以及Linux系统下的安装
Brush questions -- sword finger offer
Secsha system 1- login function
Colab works with Google cloud disk
App mobile terminal test [4] APK operation
Introduction series of software reverse cracking (1) - common configurations and function windows of xdbg32/64
Go language self-study series | if else statement in golang
App移动端测试【4】apk的操纵
Slam learning notes - build a complete gazebo multi machine simulation slam from scratch (II)
远程文件包含实操
uploads-labs靶场(附源码分析)(更新中)