image_2022-01-24_23-07-59.png
45.6 KB
#N2148. Count Elements With Strictly Smaller and Greater Elements
problem link
#solution
problem link
#solution
class Solution {
public int countElements(int[] nums) {
int min=Integer.MAX_VALUE, max=Integer.MIN_VALUE, mins=1, maxs=1;
for(int n: nums){
if(n == max){
maxs++;
}
if(n == min){
mins++;
}
if(n>max){
max = n;
maxs = 1;
}
if(n < min){
min = n;
mins = 1;
}
}
return Math.max(nums.length-mins-maxs, 0);
}
}