当前位置:网站首页>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);
}
边栏推荐
- From the 18th line to the first line, the new story of the network security industry
- Driver and application communication
- [系统安全] 四十三.Powershell恶意代码检测系列 (5)抽象语法树自动提取万字详解
- Persisting in output requires continuous learning
- 2022年Q2加密市场投融资报告:GameFi成为投资关键词
- “用Android复刻Apple产品UI”(2)——丝滑的AppStore卡片转场动画
- Advanced Mathematics (Seventh Edition) Tongji University exercises 2-1 personal solutions
- 远程文件包含实操
- June to - -------
- C language brush questions ~leetcode and simple questions of niuke.com
猜你喜欢

App移动端测试【3】ADB命令

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

Q2 encryption market investment and financing report in 2022: gamefi becomes an investment keyword

Subclass hides the function with the same name of the parent class
![[proteus simulation] 8 × 8LED dot matrix screen imitates elevator digital scrolling display](/img/46/c7f566f8fd46d383b055582d680bb7.png)
[proteus simulation] 8 × 8LED dot matrix screen imitates elevator digital scrolling display

Microservices - load balancing ribbon

Microservice API gateway

First knowledge of database

Detailed explanation of string function and string function with unlimited length

About text selection in web pages and counting the length of selected text
随机推荐
请求头不同国家和语言的表示
[redis foundation] understand redis persistence mechanism together (rdb+aof graphic explanation)
Pyinstaller is not an internal or external command, nor is it a runnable program or batch file
Intelij idea efficient skills (III)
Go language self-study series | if else if statement in golang
Slam learning notes - build a complete gazebo multi machine simulation slam from scratch (I)
App移动端测试【4】apk的操纵
Redis高可用与持久化
Pandora IOT development board learning (HAL Library) - Experiment 5 external interrupt experiment (learning notes)
Subclass hides the function with the same name of the parent class
Qt插件之自定义插件构建和使用
Download and install common programs using AUR
高等数学(第七版)同济大学 习题2-1 个人解答
“用Android复刻Apple产品UI”(3)—优雅的数据统计图表
[system safety] 43 PowerShell malicious code detection series (5) automatic extraction of ten thousand words from abstract syntax tree
uploads-labs靶场(附源码分析)(更新中)
Nine ways to define methods in scala- Nine ways to define a method in Scala?
App mobile terminal test [4] APK operation
First!! Is lancet hungry? Official documents
Find mapping relationship