forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_1491.java
More file actions
23 lines (22 loc) · 700 Bytes
/
_1491.java
File metadata and controls
23 lines (22 loc) · 700 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package com.fishercoder.solutions;
public class _1491 {
public static class Solution1 {
public double average(int[] salary) {
int max = salary[0];
int min = salary[0];
for (int i = 1; i < salary.length; i++) {
max = Math.max(max, salary[i]);
min = Math.min(min, salary[i]);
}
long total = 0;
int count = 0;
for (int i = 0; i < salary.length; i++) {
if (salary[i] != max && salary[i] != min) {
total += salary[i];
count++;
}
}
return (double) total / count;
}
}
}