Skip to content

Commit 65e071a

Browse files
authored
Improved task 2148.
1 parent a1737ce commit 65e071a

File tree

2 files changed

+20
-19
lines changed
  • src
    • main/java/g2101_2200/s2148_count_elements_with_strictly_smaller_and_greater_elements
    • test/java/g2101_2200/s2148_count_elements_with_strictly_smaller_and_greater_elements

2 files changed

+20
-19
lines changed

src/main/java/g2101_2200/s2148_count_elements_with_strictly_smaller_and_greater_elements/Solution.java

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,25 @@
33
// #Easy #Array #Sorting #2022_06_07_Time_0_ms_(100.00%)_Space_40.6_MB_(88.75%)
44

55
public class Solution {
6-
public int countElements(int[] a) {
7-
int min = a[0];
8-
int max = a[0];
6+
public int countElements(int[] nums) {
7+
int min = nums[0];
8+
int max = nums[0];
99
int minocr = 1;
1010
int maxocr = 1;
11-
for (int i = 1; i < a.length; ++i) {
12-
{
13-
if (a[i] < min) {
14-
min = a[i];
15-
minocr = 1;
16-
} else if (a[i] == min) {
17-
minocr++;
18-
}
11+
for (int i = 1; i < nums.length; ++i) {
12+
if (nums[i] < min) {
13+
min = nums[i];
14+
minocr = 1;
15+
} else if (nums[i] == min) {
16+
minocr++;
1917
}
20-
{
21-
if (a[i] > max) {
22-
max = a[i];
23-
maxocr = 1;
24-
} else if (a[i] == max) {
25-
maxocr++;
26-
}
18+
if (nums[i] > max) {
19+
max = nums[i];
20+
maxocr = 1;
21+
} else if (nums[i] == max) {
22+
maxocr++;
2723
}
2824
}
29-
return (min == max) ? 0 : a.length - minocr - maxocr;
25+
return min == max ? 0 : nums.length - minocr - maxocr;
3026
}
3127
}

src/test/java/g2101_2200/s2148_count_elements_with_strictly_smaller_and_greater_elements/SolutionTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,9 @@ void countElements() {
1515
void countElements2() {
1616
assertThat(new Solution().countElements(new int[] {-3, 3, 3, 90}), equalTo(2));
1717
}
18+
19+
@Test
20+
void countElements3() {
21+
assertThat(new Solution().countElements(new int[] {-71, -71, 93, -71, 40}), equalTo(1));
22+
}
1823
}

0 commit comments

Comments
 (0)