Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit d525bfa

Browse files
refactor 1491
1 parent d704afc commit d525bfa

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|1491|[Average Salary Excluding the Minimum and Maximum Salary](https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1491.java) | |Easy|Array, Sort|
1112
|1487|[Making File Names Unique](https://leetcode.com/problems/making-file-names-unique/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1487.java) | |Medium|HashTable, String|
1213
|1486|[XOR Operation in an Array](https://leetcode.com/problems/xor-operation-in-an-array/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1486.java) | |Medium|Array, Bit Manipulation|
1314
|1481|[Least Number of Unique Integers after K Removals](https://leetcode.com/problems/least-number-of-unique-integers-after-k-removals/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1481.java) | |Medium|Array, Sort|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.fishercoder.solutions;
2+
3+
public class _1491 {
4+
public static class Solution1 {
5+
public double average(int[] salary) {
6+
int max = salary[0];
7+
int min = salary[0];
8+
for (int i = 1; i < salary.length; i++) {
9+
max = Math.max(max, salary[i]);
10+
min = Math.min(min, salary[i]);
11+
}
12+
long total = 0;
13+
int count = 0;
14+
for (int i = 0; i < salary.length; i++) {
15+
if (salary[i] != max && salary[i] != min) {
16+
total += salary[i];
17+
count++;
18+
}
19+
}
20+
return (double) total / count;
21+
}
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.fishercoder;
2+
3+
import com.fishercoder.solutions._1491;
4+
import org.junit.BeforeClass;
5+
import org.junit.Test;
6+
7+
import static junit.framework.TestCase.assertEquals;
8+
9+
public class _1491Test {
10+
private static _1491.Solution1 solution1;
11+
private static int[] salary;
12+
13+
@BeforeClass
14+
public static void setup() {
15+
solution1 = new _1491.Solution1();
16+
}
17+
18+
@Test
19+
public void test1() {
20+
salary = new int[]{4000, 3000, 1000, 2000};
21+
assertEquals(2500.0000, solution1.average(salary));
22+
}
23+
24+
}

0 commit comments

Comments
 (0)