当前位置:网站首页>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);
}
边栏推荐
- Pychart error updating package list: connect timed out
- 【Proteus仿真】8×8LED点阵屏仿电梯数字滚动显示
- [web security] - [SQL injection] - error detection injection
- Uploads labs range (with source code analysis) (under update)
- UnityShader——MaterialCapture材质捕捉效果 (翡翠斧头)
- Redis高可用与持久化
- Slam learning notes - build a complete gazebo multi machine simulation slam from scratch (I)
- 一些事情的反思
- [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)
- Rk3399 platform development series explanation (WiFi) 5.54. What is WiFi wireless LAN
猜你喜欢

Shell script import and export data

Project -- high concurrency memory pool

QT use qzxing to generate QR code

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

The difference between calling by value and simulating calling by reference

ASEMI整流桥UMB10F参数,UMB10F规格,UMB10F封装

From the 18th line to the first line, the new story of the network security industry

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

工资3000,靠“视频剪辑”月入40000:会赚钱的人,从不靠拼命!

App移动端测试【3】ADB命令
随机推荐
The difference between calling by value and simulating calling by reference
2022年Q2加密市场投融资报告:GameFi成为投资关键词
记一次jar包冲突解决过程
《微服务设计》读书笔记(上)
Rk3399 platform development series explanation (WiFi) 5.54. What is WiFi wireless LAN
[200 opencv routines] 217 Mouse interaction to obtain polygon area (ROI)
Go language self-study series | golang switch statement
Detailed explanation of four modes of distributed transaction (Seata)
Nifi from introduction to practice (nanny level tutorial) - flow
“用Android复刻Apple产品UI”(2)——丝滑的AppStore卡片转场动画
App mobile terminal test [4] APK operation
Record a jar package conflict resolution process
Reading notes of "micro service design" (Part 2)
Redis high availability and persistence
Win32 create window and button (lightweight)
[list to map] collectors Tomap syntax sharing (case practice)
C language brush questions ~leetcode and simple questions of niuke.com
嵌入式开发:避免开源软件的7个理由
Batch files: list all files in a directory with relative paths - batch files: list all files in a directory with relative paths
Stm32f103c8t6 firmware library lighting